MCPcopy
hub / github.com/tornadoweb/tornado / _oauth_signature

Function _oauth_signature

tornado/auth.py:1155–1183  ·  view source on GitHub ↗

Calculates the HMAC-SHA1 OAuth signature for the given request. See http://oauth.net/core/1.0/#signing_process

(
    consumer_token: Dict[str, Any],
    method: str,
    url: str,
    parameters: Dict[str, Any] = {},
    token: Optional[Dict[str, Any]] = None,
)

Source from the content-addressed store, hash-verified

1153
1154
1155def _oauth_signature(
1156 consumer_token: Dict[str, Any],
1157 method: str,
1158 url: str,
1159 parameters: Dict[str, Any] = {},
1160 token: Optional[Dict[str, Any]] = None,
1161) -> bytes:
1162 """Calculates the HMAC-SHA1 OAuth signature for the given request.
1163
1164 See http://oauth.net/core/1.0/#signing_process
1165 """
1166 parts = urllib.parse.urlparse(url)
1167 scheme, netloc, path = parts[:3]
1168 normalized_url = scheme.lower() + "://" + netloc.lower() + path
1169
1170 base_elems = []
1171 base_elems.append(method.upper())
1172 base_elems.append(normalized_url)
1173 base_elems.append(
1174 "&".join(f"{k}={_oauth_escape(str(v))}" for k, v in sorted(parameters.items()))
1175 )
1176 base_string = "&".join(_oauth_escape(e) for e in base_elems)
1177
1178 key_elems = [escape.utf8(consumer_token["secret"])]
1179 key_elems.append(escape.utf8(token["secret"] if token else ""))
1180 key = b"&".join(key_elems)
1181
1182 hash = hmac.new(key, escape.utf8(base_string), hashlib.sha1)
1183 return binascii.b2a_base64(hash.digest())[:-1]
1184
1185
1186def _oauth10a_signature(

Callers 3

Calls 5

_oauth_escapeFunction · 0.85
appendMethod · 0.80
upperMethod · 0.80
joinMethod · 0.80
itemsMethod · 0.80

Tested by

no test coverage detected