o
    Df                     @   s(  d Z ddlmZ ddlmZ g dZG dd deZG dd deZG d	d
 d
eZG dd deZ	G dd deZ
G dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd  d eZG d!d" d"eZG d#d$ d$eZd%S )&a=  
    authlib.oauth2.rfc6749.errors
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Implementation for OAuth 2 Error Response. A basic error has
    parameters:

    error
         REQUIRED.  A single ASCII [USASCII] error code.

    error_description
         OPTIONAL.  Human-readable ASCII [USASCII] text providing
         additional information, used to assist the client developer in
         understanding the error that occurred.

    error_uri
         OPTIONAL.  A URI identifying a human-readable web page with
         information about the error, used to provide the client
         developer with additional information about the error.
         Values for the "error_uri" parameter MUST conform to the
         URI-reference syntax and thus MUST NOT include characters
         outside the set %x21 / %x23-5B / %x5D-7E.

    state
         REQUIRED if a "state" parameter was present in the client
         authorization request.  The exact value received from the
         client.

    https://tools.ietf.org/html/rfc6749#section-5.2

    :copyright: (c) 2017 by Hsiaoming Yang.
    )OAuth2Erroris_secure_transport)r   InsecureTransportErrorInvalidRequestErrorInvalidClientErrorUnauthorizedClientErrorInvalidGrantErrorUnsupportedResponseTypeErrorUnsupportedGrantTypeErrorInvalidScopeErrorAccessDeniedErrorMissingAuthorizationErrorUnsupportedTokenTypeErrorMissingCodeExceptionMissingTokenExceptionMissingTokenTypeExceptionMismatchingStateExceptionc                   @   s    e Zd ZdZdZedd ZdS )r   insecure_transportzOAuth 2 MUST utilize https.c                 C   s   t |s|  dS )z:Check and raise InsecureTransportError with the given URI.Nr   )clsuri r   V/home/ubuntu/webapp/venv/lib/python3.10/site-packages/authlib/oauth2/rfc6749/errors.pycheck4   s   zInsecureTransportError.checkN)__name__
__module____qualname__errordescriptionclassmethodr   r   r   r   r   r   0   s
    r   c                   @      e Zd ZdZdZdS )r   aF  The request is missing a required parameter, includes an
    unsupported parameter value (other than grant type),
    repeats a parameter, includes multiple credentials,
    utilizes more than one mechanism for authenticating the
    client, or is otherwise malformed.

    https://tools.ietf.org/html/rfc6749#section-5.2
    invalid_requestNr   r   r   __doc__r   r   r   r   r   r   ;       r   c                       s(   e Zd ZdZdZdZ fddZ  ZS )r   a}  Client authentication failed (e.g., unknown client, no
    client authentication included, or unsupported
    authentication method).  The authorization server MAY
    return an HTTP 401 (Unauthorized) status code to indicate
    which HTTP authentication schemes are supported.  If the
    client attempted to authenticate via the "Authorization"
    request header field, the authorization server MUST
    respond with an HTTP 401 (Unauthorized) status code and
    include the "WWW-Authenticate" response header field
    matching the authentication scheme used by the client.

    https://tools.ietf.org/html/rfc6749#section-5.2
    invalid_clienti  c                    s^   t   }| jdkr-|  }|dd}d| j dd| dg}|ddd| f |S )	N  "|error="error_description="WWW-AuthenticatezBasic , )superget_headersstatus_codeget_error_descriptionreplacer   appendjoin)selfheaderserror_descriptionextras	__class__r   r   r.   X   s   


zInvalidClientError.get_headers)r   r   r   r#   r   r/   r.   __classcell__r   r   r8   r   r   G   s
    r   c                   @   r    )r	   a7  The provided authorization grant (e.g., authorization
    code, resource owner credentials) or refresh token is
    invalid, expired, revoked, does not match the redirection
    URI used in the authorization request, or was issued to
    another client.

    https://tools.ietf.org/html/rfc6749#section-5.2
    invalid_grantNr"   r   r   r   r   r	   h   r$   r	   c                   @   r    )r   z The authenticated client is not authorized to use this
    authorization grant type.

    https://tools.ietf.org/html/rfc6749#section-5.2
    unauthorized_clientNr"   r   r   r   r   r   t   s    r   c                       ,   e Zd ZdZdZ fddZdd Z  ZS )r
   zZThe authorization server does not support obtaining
    an access token using this method.unsupported_response_typec                       t    || _d S N)r-   __init__response_type)r4   rB   r8   r   r   rA         

z%UnsupportedResponseTypeError.__init__c                 C      d| j  dS )Nzresponse_type= is not supported)rB   r4   r   r   r   r0         z2UnsupportedResponseTypeError.get_error_descriptionr   r   r   r#   r   rA   r0   r:   r   r   r8   r   r
   }   s
    r
   c                       r=   )r   zThe authorization grant type is not supported by the
    authorization server.

    https://tools.ietf.org/html/rfc6749#section-5.2
    unsupported_grant_typec                    r?   r@   )r-   rA   
grant_type)r4   rJ   r8   r   r   rA      rC   z"UnsupportedGrantTypeError.__init__c                 C   rD   )Nzgrant_type=rE   )rJ   rF   r   r   r   r0      rG   z/UnsupportedGrantTypeError.get_error_descriptionrH   r   r   r8   r   r      s
    r   c                   @      e Zd ZdZdZdZdS )r   zThe requested scope is invalid, unknown, malformed, or
    exceeds the scope granted by the resource owner.

    https://tools.ietf.org/html/rfc6749#section-5.2
    invalid_scopez6The requested scope is invalid, unknown, or malformed.Nr   r   r   r#   r   r   r   r   r   r   r      s    r   c                   @   rK   )r   zThe resource owner or authorization server denied the request.

    Used in authorization endpoint for "code" and "implicit". Defined in
    `Section 4.1.2.1`_.

    .. _`Section 4.1.2.1`: https://tools.ietf.org/html/rfc6749#section-4.1.2.1
    access_deniedz=The resource owner or authorization server denied the requestNrM   r   r   r   r   r      s    r   c                       s.   e Zd ZdZd fdd	Z fddZ  ZS )ForbiddenErrorr&   Nc                    s   t    || _|| _d S r@   )r-   rA   	auth_typerealm)r4   rP   rQ   r8   r   r   rA      s   

zForbiddenError.__init__c                    s   t   }| js
|S g }| jr|d| j d |d| j d | j}|d| d |d| j dd| f |S )Nzrealm="r'   r)   r*   r+    r,   )r-   r.   rP   rQ   r2   r   r   r3   )r4   r5   r7   r6   r8   r   r   r.      s   
zForbiddenError.get_headers)NN)r   r   r   r/   rA   r.   r:   r   r   r8   r   rO      s    rO   c                   @   r    )r   missing_authorizationz#Missing "Authorization" in headers.Nr   r   r   r   r   r   r   r   r   r          r   c                   @   s   e Zd ZdZdS )r   unsupported_token_typeN)r   r   r   r   r   r   r   r   r      s    r   c                   @   r    )r   missing_codezMissing "code" in response.NrT   r   r   r   r   r      rU   r   c                   @   r    )r   missing_tokenz#Missing "access_token" in response.NrT   r   r   r   r   r      rU   r   c                   @   r    )r   missing_token_typez!Missing "token_type" in response.NrT   r   r   r   r   r      rU   r   c                   @   r    )r   mismatching_statez6CSRF Warning! State not equal in request and response.NrT   r   r   r   r   r      rU   r   N)r#   authlib.oauth2.baser   authlib.common.securityr   __all__r   r   r   r	   r   r
   r   r   r   rO   r   r   r   r   r   r   r   r   r   r   <module>   s(     !	
