
    lKj&                     $    d dl mZ  G d d      Zy)   )InvalidScopeErrorc                   d    e Zd ZdZdZdddddZ	 	 ddZd Zed        Z		 	 	 	 dd	Z
	 	 	 	 dd
Zy)BearerTokenGeneratora  Bearer token generator which can create the payload for token response
    by OAuth 2 server. A typical token response would be:

    .. code-block:: http

        HTTP/1.1 200 OK
        Content-Type: application/json;charset=UTF-8
        Cache-Control: no-store
        Pragma: no-cache

        {
            "access_token":"mF_9.B5f-4.1JqM",
            "token_type":"Bearer",
            "expires_in":3600,
            "refresh_token":"tGzv3JOkF0XG5Qx2TlKWIA"
        }
    i  i / )authorization_codeimplicitpasswordclient_credentialsNc                 .    || _         || _        || _        y N)access_token_generatorrefresh_token_generatorexpires_generator)selfr   r   r   s       m/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/authlib/oauth2/rfc6750/token.py__init__zBearerTokenGenerator.__init__!   s     '=#'>$!2    c                 (   | j                   (| j                  j                  || j                        }|S t	        | j                         r| j                  ||      }|S t        | j                   t              r| j                   }|S | j                  }|S r   )r   GRANT_TYPES_EXPIRES_INgetDEFAULT_EXPIRES_INcallable
isinstanceint)r   client
grant_type
expires_ins       r   _get_expires_inz$BearerTokenGenerator._get_expires_in+   s    !!)4488D33J  d,,-//
CJ
 	 ..4//J  00Jr   c                 @    | j                  |      }|
t               |S )a  Get the allowed scope for token generation.

        Per RFC 6749 Section 3.3, if the client omits the scope parameter,
        the authorization server MUST either process the request using a
        pre-defined default value or fail the request indicating an invalid scope.

        :param client: the client making the request
        :param scope: the requested scope (may be None if omitted)
        :return: the allowed scope string
        :raises InvalidScopeError: if client.get_allowed_scope returns None
        )get_allowed_scoper   )r   scopes     r   r   z&BearerTokenGenerator.get_allowed_scope8   s'     ((/=#%%r   c                     | j                  ||      }| j                  ||||      }|| j                  ||      }d|d}|r||d<   |r$| j                  r| j                  ||||      |d<   |r||d<   |S )a  Generate a bearer token for OAuth 2.0 authorization token endpoint.

        :param client: the client that making the request.
        :param grant_type: current requested grant_type.
        :param user: current authorized user.
        :param expires_in: if provided, use this value as expires_in.
        :param scope: current requested scope.
        :param include_refresh_token: should refresh_token be included.
        :return: Token dict
        )r   r   userr    Bearer)
token_typeaccess_tokenr   refresh_tokenr    )r   r   r   r   )	r   r   r   r"   r    r   include_refresh_tokenr%   tokens	            r   generatezBearerTokenGenerator.generateJ   s    & &&vu522jt5 3 
 --fjAJ #(
 ",E, T%A%A%)%A%A*4u &B &E/" "E'Nr   c                 .    | j                  ||||||      S r   )r)   )r   r   r   r"   r    r   r'   s          r   __call__zBearerTokenGenerator.__call__r   s#     }}eZ9N
 	
r   )NN)NNNT)__name__
__module____qualname____doc__r   r   r   r   staticmethodr   r)   r+    r   r   r   r      sr    &  %$	 !%	3  * "&X "
r   r   N)rfc6749.errorsr   r   r1   r   r   <module>r3      s    .y
 y
r   