signature
This module is an implementation of section 3.4
_ of RFC 5849.
Usage
Steps for signing a request:
- Collect parameters from the request using
collect_parameters
. - Normalize those parameters using
normalize_parameters
. - Create the base string URI using
base_string_uri
. - Create the signature base string from the above three components using
signature_base_string
. - Pass the signature base string and the client credentials to one of the sign-with-client functions. The HMAC-based signing functions needs client credentials with secrets. The RSA-based signing functions needs client credentials with an RSA private key.
To verify a request, pass the request and credentials to one of the verify functions. The HMAC-based signing functions needs the shared secrets. The RSA-based verify functions needs the RSA public key.
Scope
All of the functions in this module should be considered internal to OAuthLib, since they are not imported into the "oauthlib.oauth1" module. Programs using OAuthLib should not use directly invoke any of the functions in this module.
Deprecated functions
The "sign_" methods that are not "_with_client" have been deprecated. They may be removed in a future release. Since they are all internal functions, this should have no impact on properly behaving programs.
.. _section 3.4
: https://tools.ietf.org/html/rfc5849#section-3.4
base_string_uri(uri, host=None)
Calculates the base string URI.
The base string URI is one of the components that make up the signature base string.
The host
is optional. If provided, it is used to override any host and port values in the uri
. The value for host
is usually extracted from the "Host" request header from the HTTP request. Its value may be just the hostname, or the hostname followed by a colon and a TCP/IP port number (hostname:port). If a value for thehost
is provided but it does not contain a port number, the default port number is used (i.e. if the uri
contained a port number, it will be discarded).
The rules for calculating the base string URI are defined in section 3.4.1.2`_ of RFC 5849.
.. _section 3.4.1.2
: https://tools.ietf.org/html/rfc5849#section-3.4.1.2
:param uri: URI :param host: hostname with optional port number, separated by a colon :return: base string URI
Source code in server/vendor/oauthlib/oauth1/rfc5849/signature.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
|
collect_parameters(uri_query='', body=None, headers=None, exclude_oauth_signature=True, with_realm=False)
Gather the request parameters from all the parameter sources.
This function is used to extract all the parameters, which are then passed to normalize_parameters
to produce one of the components that make up the signature base string.
Parameters starting with oauth_
will be unescaped.
Body parameters must be supplied as a dict, a list of 2-tuples, or a form encoded query string.
Headers must be supplied as a dict.
The rules where the parameters must be sourced from are defined in section 3.4.1.3.1
_ of RFC 5849.
.. _Sec 3.4.1.3.1
: https://tools.ietf.org/html/rfc5849#section-3.4.1.3.1
Source code in server/vendor/oauthlib/oauth1/rfc5849/signature.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
|
normalize_parameters(params)
Calculate the normalized request parameters.
The normalized request parameters is one of the components that make up the signature base string.
The rules for parameter normalization are defined in section 3.4.1.3.2
_ of RFC 5849.
.. _Sec 3.4.1.3.2
: https://tools.ietf.org/html/rfc5849#section-3.4.1.3.2
Source code in server/vendor/oauthlib/oauth1/rfc5849/signature.py
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 |
|
sign_hmac_sha1(base_string, client_secret, resource_owner_secret)
Deprecated function for calculating a HMAC-SHA1 signature.
This function has been replaced by invoking sign_hmac
with "SHA-1" as the hash algorithm name.
This function was invoked by sign_hmac_sha1_with_client and test_signatures.py, but does any application invoke it directly? If not, it can be removed.
Source code in server/vendor/oauthlib/oauth1/rfc5849/signature.py
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 |
|
sign_hmac_sha256(base_string, client_secret, resource_owner_secret)
Deprecated function for calculating a HMAC-SHA256 signature.
This function has been replaced by invoking sign_hmac
with "SHA-256" as the hash algorithm name.
This function was invoked by sign_hmac_sha256_with_client and test_signatures.py, but does any application invoke it directly? If not, it can be removed.
Source code in server/vendor/oauthlib/oauth1/rfc5849/signature.py
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 |
|
sign_plaintext(client_secret, resource_owner_secret)
Sign a request using plaintext.
Per section 3.4.4
_ of the spec.
The "PLAINTEXT" method does not employ a signature algorithm. It MUST be used with a transport-layer mechanism such as TLS or SSL (or sent over a secure channel with equivalent protections). It does not utilize the signature base string or the "oauth_timestamp" and "oauth_nonce" parameters.
.. _section 3.4.4
: https://tools.ietf.org/html/rfc5849#section-3.4.4
Source code in server/vendor/oauthlib/oauth1/rfc5849/signature.py
806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 |
|
sign_rsa_sha1(base_string, rsa_private_key)
Deprecated function for calculating a RSA-SHA1 signature.
This function has been replaced by invoking sign_rsa
with "SHA-1" as the hash algorithm name.
This function was invoked by sign_rsa_sha1_with_client and test_signatures.py, but does any application invoke it directly? If not, it can be removed.
Source code in server/vendor/oauthlib/oauth1/rfc5849/signature.py
758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 |
|
signature_base_string(http_method, base_str_uri, normalized_encoded_request_parameters)
Construct the signature base string.
The signature base string is the value that is calculated and signed by the client. It is also independently calculated by the server to verify the signature, and therefore must produce the exact same value at both ends or the signature won't verify.
The rules for calculating the signature base string are defined in section 3.4.1.1`_ of RFC 5849.
.. _section 3.4.1.1
: https://tools.ietf.org/html/rfc5849#section-3.4.1.1
Source code in server/vendor/oauthlib/oauth1/rfc5849/signature.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
|
verify_plaintext(request, client_secret=None, resource_owner_secret=None)
Verify a PLAINTEXT signature.
Per section 3.4
_ of the spec.
.. _section 3.4
: https://tools.ietf.org/html/rfc5849#section-3.4
Source code in server/vendor/oauthlib/oauth1/rfc5849/signature.py
841 842 843 844 845 846 847 848 849 850 851 852 |
|