
    )                         d Z ddlmZmZ ddlZddlZddlZddlmZ ddl	m
Z
mZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ  ej,                  e      Z G d de
      Zy)zoauthlib.oauth2.rfc6749.endpoint.metadata ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

An implementation of the `OAuth 2.0 Authorization Server Metadata`.

.. _`OAuth 2.0 Authorization Server Metadata`:
https://tools.ietf.org/html/rfc8414
    )absolute_importunicode_literalsN   )unicode_type   )BaseEndpointcatch_errors_and_unavailability)AuthorizationEndpoint)IntrospectEndpoint)TokenEndpoint)RevocationEndpoint   )grant_typesc                   b    e Zd ZdZi dfdZe	 	 	 dd       Z	 	 	 	 ddZd Zd Z	d	 Z
d
 Zd Zy)MetadataEndpointa  OAuth2.0 Authorization Server Metadata endpoint.

   This specification generalizes the metadata format defined by
   `OpenID Connect Discovery 1.0` in a way that is compatible
   with OpenID Connect Discovery while being applicable to a wider set
   of OAuth 2.0 use cases.  This is intentionally parallel to the way
   that OAuth 2.0 Dynamic Client Registration Protocol [`RFC7591`_]
   generalized the dynamic client registration mechanisms defined by
   OpenID Connect Dynamic Client Registration 1.0
   in a way that is compatible with it.

   .. _`OpenID Connect Discovery 1.0`:
   https://openid.net/specs/openid-connect-discovery-1_0.html
   .. _`RFC7591`: https://tools.ietf.org/html/rfc7591
   Tc                     t        |t              sJ |D ]  }t        |t              rJ  t        j                  |        || _        || _        || _        | j                         | _        y )N)	
isinstancedictr   __init__raise_errors	endpointsinitial_claimsvalidate_metadata_serverclaims)selfr   r   r   endpoints        =lib/third_party/oauthlib/oauth2/rfc6749/endpoints/metadata.pyr   zMetadataEndpoint.__init__+   sc    fd###,///  $$DDN D//1DK    Nc                 N    ddi}|t        j                  | j                        dfS )zCreate metadata responsezContent-Typezapplication/json   )jsondumpsr   )r   urihttp_methodbodyheaderss        r   create_metadata_responsez)MetadataEndpoint.create_metadata_response6   s)     12GDJJt{{+S00r   c                 t   | j                   sy ||vr|rt        dj                  |            y |rf||   j                  d      st        dj                  |||               d||   v sd||   v sd||   v rt        dj                  |||               y |r3||   j                  d      st        d	j                  |||               y |rkt	        ||   t
              st        d
j                  |||               ||   D ]1  }t	        |t              rt        dj                  |||   |             y y )Nzkey {} is a mandatory metadata.httpszkey {}: {} must be an HTTPS URL?&#z8key {}: {} must not contain query or fragment componentshttpzkey {}: {} must be an URLzkey {}: {} must be an Arrayz/array {}: {} must contains only string (not {}))r   
ValueErrorformat
startswithr   listr   )r   arraykeyis_requiredis_listis_url	is_issuerelems           r   validate_metadataz"MetadataEndpoint.validate_metadata@   sj    
%	:AA#FGG 
 
3Z""7+:AAs  		c
	cU3Z/3%*3DFMMU3Z!" 	" 4E
 
3Z""6*4;;CsLMM + 
c
D)6==c5:NOO*$$-?FFuSz4)* *  
r   c                    | j                   j                  |j                   j                                |j                  dddg       | j	                  |dd       | j	                  |dd       | j	                  |ddd       y	)
z
        If the token endpoint is used in the grant type, the value of this
        parameter MUST be the same as the value of the "grant_type"
        parameter passed to the token endpoint defined in the grant type
        definition.
        %token_endpoint_auth_methods_supportedclient_secret_postclient_secret_basicTr5   0token_endpoint_auth_signing_alg_values_supportedtoken_endpointr4   r6   N)_grant_typesextendkeys
setdefaultr9   r   r   r   s      r   validate_metadata_tokenz(MetadataEndpoint.validate_metadata_tokend   s     	X22779:
=+-BCE 	7  G:   	 d4  Ar   c           
         |j                  dt        t        d |j                  j	                                            |j                  dddg       d|d   v r| j
                  j                  d       | j                  |ddd	       | j                  |dd
       d|d   v r|j                  d   }t        |t        j                        st        |d      r|j                  }|j                  dt        |j                  j	                                      | j                  |dd
       | j                  |ddd       y )Nresponse_types_supportedc                     | dk7  S )Nnone )xs    r   <lambda>zBMetadataEndpoint.validate_metadata_authorization.<locals>.<lambda>{   s    a6kr   response_modes_supportedqueryfragmenttokenimplicitT)r4   r5   r>   codedefault_grant code_challenge_methods_supportedauthorization_endpointrA   )rE   r1   filter_response_typesrD   rB   appendr9   r   r   AuthorizationCodeGranthasattrrU   _code_challenge_methods)r   r   r   
code_grants       r   validate_metadata_authorizationz0MetadataEndpoint.validate_metadata_authorizationx   sP   
"V)8+C+C+H+H+JKLN 07J2GH
 &344
z**d  L6#=tL233++F3j
#::<@G&A9--
:Z??DDFGI

4d  D(d4  Ir   c                     |j                  dddg       | j                  |dd       | j                  |dd       | j                  |ddd       y )	N*revocation_endpoint_auth_methods_supportedr<   r=   Tr>   5revocation_endpoint_auth_signing_alg_values_supportedrevocation_endpointrA   rE   r9   rF   s      r   validate_metadata_revocationz-MetadataEndpoint.validate_metadata_revocation   sw    
B+-BCE 	<d  L?   	%4  Fr   c                     |j                  dddg       | j                  |dd       | j                  |dd       | j                  |ddd       y )	N-introspection_endpoint_auth_methods_supportedr<   r=   Tr>   8introspection_endpoint_auth_signing_alg_values_supportedintrospection_endpointrA   rd   rF   s      r   validate_metadata_introspectionz0MetadataEndpoint.validate_metadata_introspection   sw    
E+-BCE 	?  OB   	(d4  Ir   c                     t        j                  | j                        }| j                  |ddd       | j                  |dd       | j                  |dd       | j                  |dd       | j                  |d	d       | j                  |d
d       | j                  |dd       g | _        | j
                  D ]  }t        |t              r| j                  ||       t        |t              r| j                  ||       t        |t              r| j                  ||       t        |t              sz| j                  ||        |j                  d| j                         | j                  |dd       |S )a	  
        Authorization servers can have metadata describing their
        configuration.  The following authorization server metadata values
        are used by this specification. More details can be found in
        `RFC8414 section 2`_ :

       issuer
          REQUIRED

       authorization_endpoint
          URL of the authorization server's authorization endpoint
          [`RFC6749#Authorization`_].  This is REQUIRED unless no grant types
          are supported
          that use the authorization endpoint.

       token_endpoint
          URL of the authorization server's token endpoint [`RFC6749#Token`_].
          This
          is REQUIRED unless only the implicit grant type is supported.

       scopes_supported
          RECOMMENDED.

       response_types_supported
          REQUIRED.

       * Other OPTIONAL fields:
       jwks_uri
       registration_endpoint
       response_modes_supported

       grant_types_supported
          OPTIONAL.  JSON array containing a list of the OAuth 2.0 grant
          type values that this authorization server supports.  The array
          values used are the same as those used with the "grant_types"
          parameter defined by "OAuth 2.0 Dynamic Client Registration
          Protocol" [`RFC7591`_].  If omitted, the default value is
          "["authorization_code", "implicit"]".

       token_endpoint_auth_methods_supported

       token_endpoint_auth_signing_alg_values_supported

       service_documentation

       ui_locales_supported

       op_policy_uri

       op_tos_uri

       revocation_endpoint

       revocation_endpoint_auth_methods_supported

       revocation_endpoint_auth_signing_alg_values_supported

       introspection_endpoint

       introspection_endpoint_auth_methods_supported

       introspection_endpoint_auth_signing_alg_values_supported

       code_challenge_methods_supported

       Additional authorization server metadata parameters MAY also be used.
       Some are defined by other specifications, such as OpenID Connect
       Discovery 1.0 [`OpenID.Discovery`_].

        .. _`RFC8414 section 2`: https://tools.ietf.org/html/rfc8414#section-2
        .. _`RFC6749#Authorization`:
        https://tools.ietf.org/html/rfc6749#section-3.1
        .. _`RFC6749#Token`: https://tools.ietf.org/html/rfc6749#section-3.2
        .. _`RFC7591`: https://tools.ietf.org/html/rfc7591
        .. _`OpenID.Discovery`:
        https://openid.net/specs/openid-connect-discovery-1_0.html
        issuerT)r4   r7   jwks_uri)r6   scopes_supportedr>   service_documentationui_locales_supportedop_policy_uri
op_tos_urigrant_types_supported)copydeepcopyr   r9   rB   r   r   r   rG   r
   r_   r   re   r   rj   rE   rF   s      r   r   z)MetadataEndpoint.validate_metadata_server   sf   \ ]]4../F68N6:d;6#5tD6#:4H6#94H6?4@6<=DNN	Hm	,$$VX6	H3	4,,VX>	H0	1))&(;	H0	1,,VX> # -t/@/@A6#:DIMr   )GETNN)FFFF)__name__
__module____qualname____doc__r   r	   r'   r9   rG   r_   re   rj   r   rL   r   r   r   r      sd      (* 	2 # ,1$('+	1 #1 %* %$"'"*HA(I:FIfr   r   )rz   
__future__r   r   rt   r!   loggingcommonr   baser   r	   authorizationr
   
introspectr   rR   r   
revocationr    r   	getLoggerrw   logr   rL   r   r   <module>r      sM    9    # ? 0 *   * g!{| {r   