�
�cy � �4 � d Z ddlmZmZ G d� d� � ZdS )z�
oauthlib.oauth1.rfc5849
~~~~~~~~~~~~~~
This module is an implementation of various logic needed
for signing and checking OAuth 1.0 RFC 5849 requests.
� )�SIGNATURE_METHODS�utilsc �� � e Zd ZdZd� Zed� � � Zed� � � Zed� � � Zed� � � Z ed� � � Z
ed� � � Zed � � � Zed
� � � Z
ed� � � Zed� � � Zd
� Zd� Zd� Zd� Zd� Zd� Zd� Zed� � � Zed� � � Zed� � � Zd� Zd� Zd� Zd� Zd� Zd� Zd� Z d� Z!d� Z"d � Z#d!� Z$ d-d#�Z%d$� Z&d%� Z' d-d&�Z(d'� Z)d(� Z*d)� Z+d*� Z,d+� Z-d,� Z.d"S ).�RequestValidatora� 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:
* @dummy_client
* @dummy_request_token
* @dummy_access_token
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
c � � d S �N� ��selfs �K/usr/lib/python3/dist-packages/oauthlib/oauth1/rfc5849/request_validator.py�__init__zRequestValidator.__init__n s � ��� c � � t S r )r r
s r �allowed_signature_methodsz*RequestValidator.allowed_signature_methodsq s � � � r c �4 � t t j � � S r )�setr �UNICODE_ASCII_CHARACTER_SETr
s r �safe_charactersz RequestValidator.safe_charactersu s � ��5�4�5�5�5r c � � dS �N)� � r r
s r �client_key_lengthz"RequestValidator.client_key_lengthy � � ��vr c � � dS r r r
s r �request_token_lengthz%RequestValidator.request_token_length} r r c � � dS r r r
s r �access_token_lengthz$RequestValidator.access_token_length� r r c � � dS )NiX r r
s r �timestamp_lifetimez#RequestValidator.timestamp_lifetime� s � ��sr c � � dS r r r
s r �nonce_lengthzRequestValidator.nonce_length� r r c � � dS r r r
s r �verifier_lengthz RequestValidator.verifier_length� r r c � � g S r r r
s r �realmszRequestValidator.realms� s � �� r c � � dS )NTr r
s r �enforce_sslzRequestValidator.enforce_ssl� s � ��tr c � � | j \ }}t |� � | j k o|t |� � cxk o|k nc S )zCheck that the client key only contains safe characters
and is no shorter than lower and no longer than upper.
)r r r �len)r �
client_key�lower�uppers r �check_client_keyz!RequestValidator.check_client_key� sP � � �-���u��J���4�#7�7� 2���Z���1�1�1�1�E�1�1�1�1� 3r c � � | j \ }}t |� � | j k o|t |� � cxk o|k nc S )z�Checks that the request token contains only safe characters
and is no shorter than lower and no longer than upper.
)r r r r* �r �
request_tokenr, r- s r �check_request_tokenz$RequestValidator.check_request_token� sT � � �0���u��M�"�"�d�&:�:� 5���]�+�+�4�4�4�4�u�4�4�4�4� 6r c � � | j \ }}t |� � | j k o|t |� � cxk o|k nc S )z{Checks that the token contains only safe characters
and is no shorter than lower and no longer than upper.
)r r r r* r0 s r �check_access_tokenz#RequestValidator.check_access_token� sT � � �/���u��M�"�"�d�&:�:� 5���]�+�+�4�4�4�4�u�4�4�4�4� 6r c � � | j \ }}t |� � | j k o|t |� � cxk o|k nc S )z�Checks that the nonce only contains only safe characters
and is no shorter than lower and no longer than upper.
)r" |