�
&�`� � �v � d Z ddlZddlmZ ddlmZ ddlmZmZ ej e
� � Z G d� de� � ZdS ) z�
oauthlib.oauth2.rfc6749
~~~~~~~~~~~~~~~~~~~~~~~
This module is an implementation of various logic needed
for consuming and providing OAuth 2.0 RFC6749.
� N)�Request)�utils� )�BaseEndpoint�catch_errors_and_unavailabilityc � � e Zd ZdZdZd� Zed� � � Zed� � � Zed� � � Z ed� � � Z
e dd
�� � Zd� Z
d S )
�
TokenEndpointa� Token issuing endpoint.
The token endpoint is used by the client to obtain an access token by
presenting its authorization grant or refresh token. The token
endpoint is used with every authorization grant except for the
implicit grant type (since an access token is issued directly).
The means through which the client obtains the location of the token
endpoint are beyond the scope of this specification, but the location
is typically provided in the service documentation.
The endpoint URI MAY include an "application/x-www-form-urlencoded"
formatted (per `Appendix B`_) query component,
which MUST be retained when adding additional query parameters. The
endpoint URI MUST NOT include a fragment component::
https://example.com/path?query=component # OK
https://example.com/path?query=component#fragment # Not OK
Since requests to the token endpoint result in the transmission of
clear-text credentials (in the HTTP request and response), the
authorization server MUST require the use of TLS as described in
Section 1.6 when sending requests to the token endpoint::
# We will deny any request which URI schema is not with https
The client MUST use the HTTP "POST" method when making access token
requests::
# HTTP method is currently not enforced
Parameters sent without a value MUST be treated as if they were
omitted from the request. The authorization server MUST ignore
unrecognized request parameters. Request and response parameters
MUST NOT be included more than once::
# Delegated to each grant type.
.. _`Appendix B`: https://tools.ietf.org/html/rfc6749#appendix-B
)�POSTc �X � t j | � � || _ || _ || _ d S �N)r �__init__�_grant_types�_default_token_type�_default_grant_type)�self�default_grant_type�default_token_type�grant_typess �I/usr/lib/python3/dist-packages/oauthlib/oauth2/rfc6749/endpoints/token.pyr
zTokenEndpoint.__init__? s1 � ���d�#�#�#�'���#5�� �#5�� � � � c � � | j S r )r �r s r r zTokenEndpoint.grant_typesE s � �� � r c � � | j S r )r r s r r z TokenEndpoint.default_grant_typeI � � ��'�'r c �@ � | j � | j � � S r )r �getr r s r �default_grant_type_handlerz(TokenEndpoint.default_grant_type_handlerM s � ���#�#�D�$;�<�<�<r c � � | j S r )r r s r r z TokenEndpoint.default_token_typeQ r r r
Nc � � t ||||�� � }| � |� � t j |j � � |_ ||_ |r||_ |r||_ | j �
|j | j � � } t �
d|j | � � | � || j � � S )z7Extract grant_type and route to the designated handler.)�http_method�body�headersz(Dispatching grant_type %s request to %r.)r �validate_token_requestr �
scope_to_list�scope�scopes�extra_credentials�
grant_type�claimsr r r �log�debug�create_token_responser )
r �urir r! r" |