o
    ÿÑÐb•  ã                   @   s   G d d„ de ƒZdS )c                   @   sF   e Zd ZdZdZdddddœZ		ddd„Zdd	„ Z		
ddd„ZdS )ÚBearerTokenaM  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"
        }

    :param access_token_generator: a function to generate access_token.
    :param refresh_token_generator: a function to generate refresh_token,
        if not provided, refresh_token will not be added into token response.
    :param expires_generator: The expires_generator can be an int value or a
        function. If it is int, all token expires_in will be this value. If it
        is function, it can  generate expires_in depending on client and
        grant_type::

            def expires_generator(client, grant_type):
                if is_official_client(client):
                    return 3600 * 1000
                if grant_type == 'implicit':
                    return 3600
                return 3600 * 10
    :return: Callable

    When BearerToken is initialized, it will be callable::

        token_generator = BearerToken(access_token_generator)
        token = token_generator(client, grant_type, expires_in=None,
                    scope=None, include_refresh_token=True)

    The callable function that BearerToken created accepts these parameters:

    :param client: the client that making the request.
    :param grant_type: current requested grant_type.
    :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
    i  i / )Zauthorization_codeZimplicitÚpasswordZclient_credentialsNc                 C   s   || _ || _|| _d S ©N)Úaccess_token_generatorÚrefresh_token_generatorÚexpires_generator)Úselfr   r   r   © r   ú^/var/www/secure340b-portal/env/lib/python3.10/site-packages/authlib/oauth2/rfc6750/wrappers.pyÚ__init__>   s   
zBearerToken.__init__c                 C   sX   | j d u r| j || j¡}|S t| j ƒr|   ||¡}|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_inr   r   r	   Ú_get_expires_inE   s   
ÿ
úüÿzBearerToken._get_expires_inTc           	      C   s^   |   ||||¡}|d u r|  ||¡}d||dœ}|r'| jr'|  ||||¡|d< |r-||d< |S )NZBearer)Ú
token_typeÚaccess_tokenr   Zrefresh_tokenÚscope)r   r   r   )	r   r   r   Úuserr   r   Zinclude_refresh_tokenr   Útokenr   r   r	   Ú__call__Q   s   ý
ÿzBearerToken.__call__)NN)NNNT)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r
   r   r   r   r   r   r	   r      s    2ü
þÿr   N)Úobjectr   r   r   r   r	   Ú<module>   s   