
    D6i                         d dl mZ d dlmZ d dlmZ d dlmZ dZdZ	dZ
dZd	Z	 	 dd
d
dd
d
d
d
dd
d	dZ ed       Z G d de      Zy
)    )g)WebApplicationClient)
LocalProxy)OAuth2ConsumerBlueprintz%Ryan Schaffer <schaffer.ry@gmail.com>auth_headerquerybodyzZoho-oauthtokenNF)	scoperedirect_urlofflineredirect_to	login_urlsession_classstoragereprompt_consentrule_kwargsc       	            |xs dg}d}t        | t              }i }|rdnd|d<   |	rd|d<   t        d	t        | ||||d
d|||||||
      dj                  d<   dj                  d<   j
                  fd       }S )a  
    Make a blueprint for authenticating with Zoho using OAuth 2. This requires
    a client ID and client secret from Zoho. You should either pass them to
    this constructor, or make sure that your Flask application config defines
    them, using the variables :envvar:`ZOHO_OAUTH_CLIENT_ID` and
    :envvar:`ZOHO_OAUTH_CLIENT_SECRET`.
    IMPORTANT: Configuring the base_url is not supported in this config.

    Args:
        client_id (str): The client ID for your application on Zoho.
        client_secret (str): The client secret for your application on Zoho
        scope (list, optional): list of scopes (str) for the OAuth token
        redirect_url (str): the URL to redirect to after the authentication
            dance is complete
        redirect_to (str): if ``redirect_url`` is not defined, the name of the
            view to redirect to after the authentication dance is complete.
            The actual URL will be determined by :func:`flask.url_for`
        login_url (str, optional): the URL path for the ``login`` view.
            Defaults to ``/zoho``
        authorized_url (str, optional): the URL path for the ``authorized`` view.
            Defaults to ``/zoho/authorized``.
        session_class (class, optional): The class to use for creating a
            Requests session. Defaults to
            :class:`~flask_dance.consumer.requests.OAuth2Session`.
        storage: A token storage class, or an instance of a token storage
                class, to use for this blueprint. Defaults to
                :class:`~flask_dance.consumer.storage.session.SessionStorage`.
        offline (bool): Whether to request `offline access`
            for the OAuth token. Defaults to False
        reprompt_consent (bool): If True, force Zoho to re-prompt the user
            for their consent, even if the user has already given their
            consent. Defaults to False.
        rule_kwargs (dict, optional): Additional arguments that should be passed when adding
            the login and authorized routes. Defaults to ``None``.

    :rtype: :class:`~flask_dance.consumer.OAuth2ConsumerBlueprint`
    :returns: A :doc:`blueprint <flask:blueprints>` to attach to your Flask app.
    zZohoCRM.users.allzhttps://www.zohoapis.com/)
token_typer   onlineaccess_typeconsentpromptzohoz(https://accounts.zoho.com/oauth/v2/tokenz'https://accounts.zoho.com/oauth/v2/auth)	client_idclient_secretclientr
   base_url	token_urlauthorization_urlauthorization_url_paramsr   r   r   r   r   r   ZOHO_OAUTH_CLIENT_IDr   ZOHO_OAUTH_CLIENT_SECRETr   c                  0     j                   t        _        y N)sessionr   flask_dance_zoho)zoho_bps   [/home/azureuser/techstart-app/venv/lib/python3.12/site-packages/flask_dance/contrib/zoho.pyset_applocal_sessionz1make_zoho_blueprint.<locals>.set_applocal_session`   s    $__    )ZohoWebClientZOHO_TOKEN_HEADERr   __name__from_configbefore_app_request)r   r   r
   r   r   r   r   r   r   r   r   r   r   r    r)   r'   s                  @r(   make_zoho_blueprintr0      s    h *)*E*H91BCF!;Bi]+-6 *%#<C!9!#!G& (>G$+EG(-  - Nr*   c                  "    t         j                  S r$   )r   r&    r*   r(   <lambda>r3   g   s    !,, r*   c                   <    e Zd ZdZed        Z	 ddZedd       Zy)r+   zJ
    Remove the requirement that token_types adhere to OAuth Standard
    c                 V    d| j                   d| j                  t        | j                  iS )NBearerMAC)_add_bearer_token_add_mac_tokenr,   _add_zoho_token)selfs    r(   token_typeszZohoWebClient.token_typeso   s/     d,,4&&t33
 	
r*   Nc                 D    | j                  | j                  |      }|||fS )zYAdd a zoho token to the request uri, body or authorization header. follows bearer pattern)prepare_zoho_headersaccess_token)r;   urihttp_methodr	   headerstoken_placements         r(   r:   zZohoWebClient._add_zoho_tokenw   s)     ++D,=,=wGGT!!r*   c                 F    |xs i }dj                  t        |       |d<   |S )zAdd a `Zoho Token`_ to the request URI.
        Recommended method of passing bearer tokens.

        Authorization: Zoho-oauthtoken h480djs93hd8

        .. _`Zoho-oauthtoken Token`: custom zoho token
        z{token_header} {token})token_headertokenAuthorization)formatr,   )rF   rB   s     r(   r>   z"ZohoWebClient.prepare_zoho_headers~   s4     -R#;#B#B*% $C $
  r*   )GETNNNr$   )	r-   
__module____qualname____doc__propertyr<   r:   staticmethodr>   r2   r*   r(   r+   r+   j   s;     
 
 PT"  r*   r+   )NN)flaskr   /oauthlib.oauth2.rfc6749.clients.web_applicationr   werkzeug.localr   flask_dance.consumerr   __maintainer__AUTH_HEADER	URI_QUERYBODYr,   r0   r   r+   r2   r*   r(   <module>rW      sw     P % 88	%  U Up ,-!( !r*   