request_validator
oauthlib.oauth1.rfc5849 ~~~~~~~~~~~~~~
This module is an implementation of various logic needed for signing and checking OAuth 1.0 RFC 5849 requests.
RequestValidator
A validator/datastore interaction base class for OAuth 1 providers.
OAuth providers should inherit from RequestValidator and implement the methods and properties outlined below. Further details are provided in the documentation for each method and property.
Methods used to check the format of input parameters. Common tests include length, character set, membership, range or pattern. These tests are referred to as whitelisting or blacklisting
_. Whitelisting is better but blacklisting can be useful to spot malicious activity. The following have methods a default implementation:
- check_client_key
- check_request_token
- check_access_token
- check_nonce
- check_verifier
- check_realms
The methods above default to whitelist input parameters, checking that they are alphanumerical and between a minimum and maximum length. Rather than overloading the methods a few properties can be used to configure these methods.
- @safe_characters -> (character set)
- @client_key_length -> (min, max)
- @request_token_length -> (min, max)
- @access_token_length -> (min, max)
- @nonce_length -> (min, max)
- @verifier_length -> (min, max)
- @realms -> [list, of, realms]
Methods used to validate/invalidate input parameters. These checks usually hit either persistent or temporary storage such as databases or the filesystem. See each methods documentation for detailed usage. The following methods must be implemented:
- validate_client_key
- validate_request_token
- validate_access_token
- validate_timestamp_and_nonce
- validate_redirect_uri
- validate_requested_realms
- validate_realms
- validate_verifier
- invalidate_request_token
Methods used to retrieve sensitive information from storage. The following methods must be implemented:
- get_client_secret
- get_request_token_secret
- get_access_token_secret
- get_rsa_key
- get_realms
- get_default_realms
- get_redirect_uri
Methods used to save credentials. The following methods must be implemented:
- save_request_token
- save_verifier
- save_access_token
Methods used to verify input parameters. This methods are used during authorizing request token by user (AuthorizationEndpoint), to check if parameters are valid. During token authorization request is not signed, thus 'validation' methods can not be used. The following methods must be implemented:
- verify_realms
- verify_request_token
To prevent timing attacks it is necessary to not exit early even if the client key or resource owner key is invalid. Instead dummy values should be used during the remaining verification process. It is very important that the dummy client and token are valid input parameters to the methods get_client_secret, get_rsa_key and get_(access/request)_token_secret and that the running time of those methods when given a dummy value remain equivalent to the running time when given a valid client/resource owner. The following properties must be implemented:
Example implementations have been provided, note that the database used is a simple dictionary and serves only an illustrative purpose. Use whichever database suits your project and how to access it is entirely up to you. The methods are introduced in an order which should make understanding their use more straightforward and as such it could be worth reading what follows in chronological order.
.. _whitelisting or blacklisting
: https://www.schneier.com/blog/archives/2011/01/whitelisting_vs.html
Source code in server/vendor/oauthlib/oauth1/rfc5849/request_validator.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 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 103 104 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 235 236 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 322 323 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 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 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 839 840 841 842 843 844 845 846 847 848 849 |
|
dummy_access_token
property
Dummy access token used when an invalid token was supplied.
:returns: The dummy access token string.
The dummy access token should be associated with an access token secret such that get_access_token_secret(.., dummy_access_token) returns a valid secret.
This method is used by
- ResourceEndpoint
dummy_client
property
Dummy client used when an invalid client key is supplied.
:returns: The dummy client key string.
The dummy client should be associated with either a client secret, a rsa key or both depending on which signature methods are supported. Providers should make sure that
get_client_secret(dummy_client) get_rsa_key(dummy_client)
return a valid secret or key for the dummy client.
This method is used by
- AccessTokenEndpoint
- RequestTokenEndpoint
- ResourceEndpoint
- SignatureOnlyEndpoint
dummy_request_token
property
Dummy request token used when an invalid token was supplied.
:returns: The dummy request token string.
The dummy request token should be associated with a request token secret such that get_request_token_secret(.., dummy_request_token) returns a valid secret.
This method is used by
- AccessTokenEndpoint
check_access_token(request_token)
Checks that the token contains only safe characters and is no shorter than lower and no longer than upper.
Source code in server/vendor/oauthlib/oauth1/rfc5849/request_validator.py
169 170 171 172 173 174 175 |
|
check_client_key(client_key)
Check that the client key only contains safe characters and is no shorter than lower and no longer than upper.
Source code in server/vendor/oauthlib/oauth1/rfc5849/request_validator.py
153 154 155 156 157 158 159 |
|
check_nonce(nonce)
Checks that the nonce only contains only safe characters and is no shorter than lower and no longer than upper.
Source code in server/vendor/oauthlib/oauth1/rfc5849/request_validator.py
177 178 179 180 181 182 183 |
|
check_realms(realms)
Check that the realm is one of a set allowed realms.
Source code in server/vendor/oauthlib/oauth1/rfc5849/request_validator.py
193 194 195 |
|
check_request_token(request_token)
Checks that the request token contains only safe characters and is no shorter than lower and no longer than upper.
Source code in server/vendor/oauthlib/oauth1/rfc5849/request_validator.py
161 162 163 164 165 166 167 |
|
check_verifier(verifier)
Checks that the verifier contains only safe characters and is no shorter than lower and no longer than upper.
Source code in server/vendor/oauthlib/oauth1/rfc5849/request_validator.py
185 186 187 188 189 190 191 |
|
get_access_token_secret(client_key, token, request)
Retrieves the shared secret associated with the access token.
:param client_key: The client/consumer key. :param token: The access token string. :param request: OAuthlib request. :type request: oauthlib.common.Request :returns: The token secret as a string.
This method must allow the use of a dummy values and the running time must be roughly equivalent to that of the running time of valid values::
# Unlikely to be near constant time as it uses two database
# lookups for a valid client, and only one for an invalid.
from your_datastore import AccessTokenSecret
if AccessTokenSecret.has(client_key):
return AccessTokenSecret.get((client_key, request_token))
else:
return 'dummy'
# Aim to mimic number of latency inducing operations no matter
# whether the client is valid or not.
from your_datastore import AccessTokenSecret
return ClientSecret.get((client_key, request_token), 'dummy')
Note that the returned key must be in plaintext.
This method is used by
- ResourceEndpoint
Source code in server/vendor/oauthlib/oauth1/rfc5849/request_validator.py
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 |
|
get_client_secret(client_key, request)
Retrieves the client secret associated with the client key.
:param client_key: The client/consumer key. :param request: OAuthlib request. :type request: oauthlib.common.Request :returns: The client secret as a string.
This method must allow the use of a dummy client_key value. Fetching the secret using the dummy key must take the same amount of time as fetching a secret for a valid client::
# Unlikely to be near constant time as it uses two database
# lookups for a valid client, and only one for an invalid.
from your_datastore import ClientSecret
if ClientSecret.has(client_key):
return ClientSecret.get(client_key)
else:
return 'dummy'
# Aim to mimic number of latency inducing operations no matter
# whether the client is valid or not.
from your_datastore import ClientSecret
return ClientSecret.get(client_key, 'dummy')
Note that the returned key must be in plaintext.
This method is used by
- AccessTokenEndpoint
- RequestTokenEndpoint
- ResourceEndpoint
- SignatureOnlyEndpoint
Source code in server/vendor/oauthlib/oauth1/rfc5849/request_validator.py
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 |
|
get_default_realms(client_key, request)
Get the default realms for a client.
:param client_key: The client/consumer key. :param request: OAuthlib request. :type request: oauthlib.common.Request :returns: The list of default realms associated with the client.
The list of default realms will be set during client registration and is outside the scope of OAuthLib.
This method is used by
- RequestTokenEndpoint
Source code in server/vendor/oauthlib/oauth1/rfc5849/request_validator.py
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
|
get_realms(token, request)
Get realms associated with a request token.
:param token: The request token string. :param request: OAuthlib request. :type request: oauthlib.common.Request :returns: The list of realms associated with the request token.
This method is used by
- AuthorizationEndpoint
- AccessTokenEndpoint
Source code in server/vendor/oauthlib/oauth1/rfc5849/request_validator.py
380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
|
get_redirect_uri(token, request)
Get the redirect URI associated with a request token.
:param token: The request token string. :param request: OAuthlib request. :type request: oauthlib.common.Request :returns: The redirect URI associated with the request token.
It may be desirable to return a custom URI if the redirect is set to "oob". In this case, the user will be redirected to the returned URI and at that endpoint the verifier can be displayed.
This method is used by
- AuthorizationEndpoint
Source code in server/vendor/oauthlib/oauth1/rfc5849/request_validator.py
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
|
get_request_token_secret(client_key, token, request)
Retrieves the shared secret associated with the request token.
:param client_key: The client/consumer key. :param token: The request token string. :param request: OAuthlib request. :type request: oauthlib.common.Request :returns: The token secret as a string.
This method must allow the use of a dummy values and the running time must be roughly equivalent to that of the running time of valid values::
# Unlikely to be near constant time as it uses two database
# lookups for a valid client, and only one for an invalid.
from your_datastore import RequestTokenSecret
if RequestTokenSecret.has(client_key):
return RequestTokenSecret.get((client_key, request_token))
else:
return 'dummy'
# Aim to mimic number of latency inducing operations no matter
# whether the client is valid or not.
from your_datastore import RequestTokenSecret
return ClientSecret.get((client_key, request_token), 'dummy')
Note that the returned key must be in plaintext.
This method is used by
- AccessTokenEndpoint
Source code in server/vendor/oauthlib/oauth1/rfc5849/request_validator.py
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 322 323 324 325 326 327 328 |
|
get_rsa_key(client_key, request)
Retrieves a previously stored client provided RSA key.
:param client_key: The client/consumer key. :param request: OAuthlib request. :type request: oauthlib.common.Request :returns: The rsa public key as a string.
This method must allow the use of a dummy client_key value. Fetching the rsa key using the dummy key must take the same amount of time as fetching a key for a valid client. The dummy key must also be of the same bit length as client keys.
Note that the key must be returned in plaintext.
This method is used by
- AccessTokenEndpoint
- RequestTokenEndpoint
- ResourceEndpoint
- SignatureOnlyEndpoint
Source code in server/vendor/oauthlib/oauth1/rfc5849/request_validator.py
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 |
|
invalidate_request_token(client_key, request_token, request)
Invalidates a used request token.
:param client_key: The client/consumer key. :param request_token: The request token string. :param request: OAuthlib request. :type request: oauthlib.common.Request :returns: None
Per Section 2.3
_ of the spec:
"The server MUST (...) ensure that the temporary credentials have not expired or been used before."
.. _Section 2.3
: https://tools.ietf.org/html/rfc5849#section-2.3
This method should ensure that provided token won't validate anymore. It can be simply removing RequestToken from storage or setting specific flag that makes it invalid (note that such flag should be also validated during request token validation).
This method is used by
- AccessTokenEndpoint
Source code in server/vendor/oauthlib/oauth1/rfc5849/request_validator.py
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 |
|
save_access_token(token, request)
Save an OAuth1 access token.
:param token: A dict with token credentials. :param request: OAuthlib request. :type request: oauthlib.common.Request
The token dictionary will at minimum include
oauth_token
the access token string.oauth_token_secret
the token specific secret used in signing.oauth_authorized_realms
a space separated list of realms.
Client key can be obtained from request.client_key
.
The list of realms (not joined string) can be obtained from request.realm
.
This method is used by
- AccessTokenEndpoint
Source code in server/vendor/oauthlib/oauth1/rfc5849/request_validator.py
785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 |
|
save_request_token(token, request)
Save an OAuth1 request token.
:param token: A dict with token credentials. :param request: OAuthlib request. :type request: oauthlib.common.Request
The token dictionary will at minimum include
oauth_token
the request token string.oauth_token_secret
the token specific secret used in signing.oauth_callback_confirmed
the stringtrue
.
Client key can be obtained from request.client_key
.
This method is used by
- RequestTokenEndpoint
Source code in server/vendor/oauthlib/oauth1/rfc5849/request_validator.py
809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 |
|
save_verifier(token, verifier, request)
Associate an authorization verifier with a request token.
:param token: A request token string. :param verifier: A dictionary containing the oauth_verifier and oauth_token :param request: OAuthlib request. :type request: oauthlib.common.Request
We need to associate verifiers with tokens for validation during the access token request.
Note that unlike save_x_token token here is the oauth_token
token string from the request token saved previously.
This method is used by
- AuthorizationEndpoint
Source code in server/vendor/oauthlib/oauth1/rfc5849/request_validator.py
830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 |
|
validate_access_token(client_key, token, request)
Validates that supplied access token is registered and valid.
:param client_key: The client/consumer key. :param token: The access token string. :param request: OAuthlib request. :type request: oauthlib.common.Request :returns: True or False
Note that if the dummy access token is supplied it should validate in the same or nearly the same amount of time as a valid one.
Ensure latency inducing tasks are mimiced even for dummy clients. For example, use::
from your_datastore import AccessToken
try:
return AccessToken.exists(client_key, access_token)
except DoesNotExist:
return False
Rather than::
from your_datastore import AccessToken
if access_token == self.dummy_access_token:
return False
else:
return AccessToken.exists(client_key, access_token)
This method is used by
- ResourceEndpoint
Source code in server/vendor/oauthlib/oauth1/rfc5849/request_validator.py
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 |
|
validate_client_key(client_key, request)
Validates that supplied client key is a registered and valid client.
:param client_key: The client/consumer key. :param request: OAuthlib request. :type request: oauthlib.common.Request :returns: True or False
Note that if the dummy client is supplied it should validate in same or nearly the same amount of time as a valid one.
Ensure latency inducing tasks are mimiced even for dummy clients. For example, use::
from your_datastore import Client
try:
return Client.exists(client_key, access_token)
except DoesNotExist:
return False
Rather than::
from your_datastore import Client
if access_token == self.dummy_access_token:
return False
else:
return Client.exists(client_key, access_token)
This method is used by
- AccessTokenEndpoint
- RequestTokenEndpoint
- ResourceEndpoint
- SignatureOnlyEndpoint
Source code in server/vendor/oauthlib/oauth1/rfc5849/request_validator.py
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 |
|
validate_realms(client_key, token, request, uri=None, realms=None)
Validates access to the request realm.
:param client_key: The client/consumer key. :param token: A request token string. :param request: OAuthlib request. :type request: oauthlib.common.Request :param uri: The URI the realms is protecting. :param realms: A list of realms that must have been granted to the access token. :returns: True or False
How providers choose to use the realm parameter is outside the OAuth specification but it is commonly used to restrict access to a subset of protected resources such as "photos".
realms is a convenience parameter which can be used to provide a per view method pre-defined list of allowed realms.
Can be as simple as::
from your_datastore import RequestToken
request_token = RequestToken.get(token, None)
if not request_token:
return False
return set(request_token.realms).issuperset(set(realms))
This method is used by
- ResourceEndpoint
Source code in server/vendor/oauthlib/oauth1/rfc5849/request_validator.py
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 |
|
validate_redirect_uri(client_key, redirect_uri, request)
Validates the client supplied redirection URI.
:param client_key: The client/consumer key. :param redirect_uri: The URI the client which to redirect back to after authorization is successful. :param request: OAuthlib request. :type request: oauthlib.common.Request :returns: True or False
It is highly recommended that OAuth providers require their clients to register all redirection URIs prior to using them in requests and register them as absolute URIs. See CWE-601
_ for more information about open redirection attacks.
By requiring registration of all redirection URIs it should be straightforward for the provider to verify whether the supplied redirect_uri is valid or not.
Alternatively per Section 2.1
_ of the spec:
"If the client is unable to receive callbacks or a callback URI has been established via other means, the parameter value MUST be set to "oob" (case sensitive), to indicate an out-of-band configuration."
.. CWE-601
: http://cwe.mitre.org/top25/index.html#CWE-601 .. Section 2.1
: https://tools.ietf.org/html/rfc5849#section-2.1
This method is used by
- RequestTokenEndpoint
Source code in server/vendor/oauthlib/oauth1/rfc5849/request_validator.py
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 |
|
validate_request_token(client_key, token, request)
Validates that supplied request token is registered and valid.
:param client_key: The client/consumer key. :param token: The request token string. :param request: OAuthlib request. :type request: oauthlib.common.Request :returns: True or False
Note that if the dummy request_token is supplied it should validate in the same nearly the same amount of time as a valid one.
Ensure latency inducing tasks are mimiced even for dummy clients. For example, use::
from your_datastore import RequestToken
try:
return RequestToken.exists(client_key, access_token)
except DoesNotExist:
return False
Rather than::
from your_datastore import RequestToken
if access_token == self.dummy_access_token:
return False
else:
return RequestToken.exists(client_key, access_token)
This method is used by
- AccessTokenEndpoint
Source code in server/vendor/oauthlib/oauth1/rfc5849/request_validator.py
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 |
|
validate_requested_realms(client_key, realms, request)
Validates that the client may request access to the realm.
:param client_key: The client/consumer key. :param realms: The list of realms that client is requesting access to. :param request: OAuthlib request. :type request: oauthlib.common.Request :returns: True or False
This method is invoked when obtaining a request token and should tie a realm to the request token and after user authorization this realm restriction should transfer to the access token.
This method is used by
- RequestTokenEndpoint
Source code in server/vendor/oauthlib/oauth1/rfc5849/request_validator.py
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 |
|
validate_timestamp_and_nonce(client_key, timestamp, nonce, request, request_token=None, access_token=None)
Validates that the nonce has not been used before.
:param client_key: The client/consumer key. :param timestamp: The oauth_timestamp
parameter. :param nonce: The oauth_nonce
parameter. :param request_token: Request token string, if any. :param access_token: Access token string, if any. :param request: OAuthlib request. :type request: oauthlib.common.Request :returns: True or False
Per Section 3.3
_ of the spec.
"A nonce is a random string, uniquely generated by the client to allow the server to verify that a request has never been made before and helps prevent replay attacks when requests are made over a non-secure channel. The nonce value MUST be unique across all requests with the same timestamp, client credentials, and token combinations."
.. _Section 3.3
: https://tools.ietf.org/html/rfc5849#section-3.3
One of the first validation checks that will be made is for the validity of the nonce and timestamp, which are associated with a client key and possibly a token. If invalid then immediately fail the request by returning False. If the nonce/timestamp pair has been used before and you may just have detected a replay attack. Therefore it is an essential part of OAuth security that you not allow nonce/timestamp reuse. Note that this validation check is done before checking the validity of the client and token.::
nonces_and_timestamps_database = [ (u'foo', 1234567890, u'rannoMstrInghere', u'bar') ]
def validate_timestamp_and_nonce(self, client_key, timestamp, nonce, request_token=None, access_token=None):
return ((client_key, timestamp, nonce, request_token or access_token)
not in self.nonces_and_timestamps_database)
This method is used by
- AccessTokenEndpoint
- RequestTokenEndpoint
- ResourceEndpoint
- SignatureOnlyEndpoint
Source code in server/vendor/oauthlib/oauth1/rfc5849/request_validator.py
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 |
|
validate_verifier(client_key, token, verifier, request)
Validates a verification code.
:param client_key: The client/consumer key. :param token: A request token string. :param verifier: The authorization verifier string. :param request: OAuthlib request. :type request: oauthlib.common.Request :returns: True or False
OAuth providers issue a verification code to clients after the resource owner authorizes access. This code is used by the client to obtain token credentials and the provider must verify that the verifier is valid and associated with the client as well as the resource owner.
Verifier validation should be done in near constant time (to avoid verifier enumeration). To achieve this we need a constant time string comparison which is provided by OAuthLib in oauthlib.common.safe_string_equals
::
from your_datastore import Verifier
correct_verifier = Verifier.get(client_key, request_token)
from oauthlib.common import safe_string_equals
return safe_string_equals(verifier, correct_verifier)
This method is used by
- AccessTokenEndpoint
Source code in server/vendor/oauthlib/oauth1/rfc5849/request_validator.py
710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 |
|
verify_realms(token, realms, request)
Verify authorized realms to see if they match those given to token.
:param token: An access token string. :param realms: A list of realms the client attempts to access. :param request: OAuthlib request. :type request: oauthlib.common.Request :returns: True or False
This prevents the list of authorized realms sent by the client during the authorization step to be altered to include realms outside what was bound with the request token.
Can be as simple as::
valid_realms = self.get_realms(token)
return all((r in valid_realms for r in realms))
This method is used by
- AuthorizationEndpoint
Source code in server/vendor/oauthlib/oauth1/rfc5849/request_validator.py
761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 |
|
verify_request_token(token, request)
Verify that the given OAuth1 request token is valid.
:param token: A request token string. :param request: OAuthlib request. :type request: oauthlib.common.Request :returns: True or False
This method is used only in AuthorizationEndpoint to check whether the oauth_token given in the authorization URL is valid or not. This request is not signed and thus similar validate_request_token
method can not be used.
This method is used by
- AuthorizationEndpoint
Source code in server/vendor/oauthlib/oauth1/rfc5849/request_validator.py
742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 |
|