B
    ]\0                 @   s0   d dl Z d dlmZ G dd deZdd ZdS )    N)	deprecatec               @   s>   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	   w/private/var/folders/pf/vfcx6ndx4k5bb3vdnp68mdb40000gn/T/pip-install-6fjfx5ra/authlib/authlib/specs/rfc6750/wrappers.py__init__A   s    zBearerToken.__init__c             C   sR   | j d kr| j|| j}n2t| j r4|  ||}nt| j trH| j }n| j}|S )N)r   GRANT_TYPES_EXPIRES_INgetDEFAULT_EXPIRES_INcallable
isinstanceint)r   client
grant_type
expires_inr	   r	   r
   _get_expires_inH   s    

zBearerToken._get_expires_inTc       	      C   sb   t | j||||}|d kr&| ||}d||d}|rR| jrRt | j|||||d< |r^||d< |S )NZBearer)
token_typeaccess_tokenr   Zrefresh_tokenscope)
_gen_tokenr   r   r   )	r   r   r   userr   r   Zinclude_refresh_tokenr   tokenr	   r	   r
   __call__T   s    
zBearerToken.__call__)NN)NNNT)	__name__
__module____qualname____doc__r   r   r   r   r   r	   r	   r	   r
   r      s   0 
 r   c             C   sh   t tdr&t| }|j o"|j }nt| }|j o>|j }|rXtdddd |  S | ||||dS )Ngetfullargspecz&Token generator now accepts parametersz0.11ZvhL75tg)r   r   r   r   )hasattrinspectr!   argsvarkw
getargspeckeywordsr   )funcr   r   r   r   specZno_argsr	   r	   r
   r   n   s    


r   )r$   Zauthlib.deprecater   objectr   r   r	   r	   r	   r
   <module>   s   i