
    g6                         d Z ddlZddlZddlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddlm
Z
 dZ G d	 d
ej                  ej                  ej                        Zy)a  External Account Authorized User Credentials.
This module provides credentials based on OAuth 2.0 access and refresh tokens.
These credentials usually access resources on behalf of a user (resource
owner).

Specifically, these are sourced using external identities via Workforce Identity Federation.

Obtaining the initial access and refresh token can be done through the Google Cloud CLI.

Example credential:
{
  "type": "external_account_authorized_user",
  "audience": "//iam.googleapis.com/locations/global/workforcePools/$WORKFORCE_POOL_ID/providers/$PROVIDER_ID",
  "refresh_token": "refreshToken",
  "token_url": "https://sts.googleapis.com/v1/oauth/token",
  "token_info_url": "https://sts.googleapis.com/v1/instrospect",
  "client_id": "clientId",
  "client_secret": "clientSecret"
}
    N)_helpers)credentials)
exceptions)sts)utils external_account_authorized_userc                   h    e Zd ZdZdddddddddddej
                  f fd	Zed        Zd Z	ed        Z
ed        Zed        Zed	        Zed
        Zed        Zed        Zed        Zed        Zed        Zed        ZddZddZd Zd Z ej4                  ej6                        d        Zd Z ej4                  ej<                        d        Z ej4                  ej@                        d        Z! ej4                  ejD                        d        Z#e$d        Z%e$d        Z& xZ'S )Credentialsa  Credentials for External Account Authorized Users.

    This is used to instantiate Credentials for exchanging refresh tokens from
    authorized users for Google access token and authorizing requests to Google
    APIs.

    The credentials are considered immutable. If you want to modify the
    quota project, use `with_quota_project` and if you want to modify the token
    uri, use `with_token_uri`.
    Nc                 r   t         t        |           || _        || _        || _        || _        || _        || _        || _	        || _
        |	| _        || _        |
| _        |xs t        j                  | _        d| _        | j$                  s!| j&                  st)        j*                  d      d| _        | j                  rHt/        j0                  t.        j2                  j4                  | j                  | j                        | _        t7        j8                  | j                  | j,                        | _        y)a  Instantiates a external account authorized user credentials object.

        Args:
        token (str): The OAuth 2.0 access token. Can be None if refresh information
            is provided.
        expiry (datetime.datetime): The optional expiration datetime of the OAuth 2.0 access
            token.
        refresh_token (str): The optional OAuth 2.0 refresh token. If specified,
            credentials can be refreshed.
        audience (str): The optional STS audience which contains the resource name for the workforce
            pool and the provider identifier in that pool.
        client_id (str): The OAuth 2.0 client ID. Must be specified for refresh, can be left as
            None if the token can not be refreshed.
        client_secret (str): The OAuth 2.0 client secret. Must be specified for refresh, can be
            left as None if the token can not be refreshed.
        token_url (str): The optional STS token exchange endpoint for refresh. Must be specified for
            refresh, can be left as None if the token can not be refreshed.
        token_info_url (str): The optional STS endpoint URL for token introspection.
        revoke_url (str): The optional STS endpoint URL for revoking tokens.
        quota_project_id (str): The optional project ID used for quota and billing.
            This project may be different from the project used to
            create the credentials.
        universe_domain (Optional[str]): The universe domain. The default value
            is googleapis.com.

        Returns:
            google.auth.external_account_authorized_user.Credentials: The
                constructed credentials.
        NzToken should be created with fields to make it valid (`token` and `expiry`), or fields to allow it to refresh (`refresh_token`, `token_url`, `client_id`, `client_secret`).)superr
   __init__tokenexpiry	_audience_refresh_token
_token_url_token_info_url
_client_id_client_secret_revoke_url_quota_project_id_scopesr   DEFAULT_UNIVERSE_DOMAIN_universe_domain_cred_file_pathvalidcan_refreshr   InvalidOperation_client_authr   ClientAuthenticationClientAuthTypebasicr   Client_sts_client)selfr   r   refresh_tokenaudience	client_idclient_secret	token_urltoken_info_url
revoke_urlscopesquota_project_iduniverse_domain	__class__s                /var/www/html/FastMealFinder_FlaskServer-InitialRelease/venv/lib/python3.12/site-packages/google/auth/external_account_authorized_user.pyr   zCredentials.__init__A   s   X 	k4)+
!+#-#+%!1 / V;3V3V#zz$"2"2-->  !?? % : :$$**DOOT=P=P!D ::doot7H7HI    c                     | j                         }|j                  t               |d   r|d   j                         dz   |d<   |j	                         D ci c]  \  }}|	|| c}}S c c}}w )a  Generates the serializable dictionary representation of the current
        credentials.

        Returns:
            Mapping: The dictionary representation of the credentials. This is the
                reverse of the "from_info" method defined in this class. It is
                useful for serializing the current credentials so it can deserialized
                later.
        )typer   Z)constructor_argsupdate+_EXTERNAL_ACCOUNT_AUTHORIZED_USER_JSON_TYPE	isoformatitems)r%   config_infokeyvalues       r1   infozCredentials.info   ss     ++- KLx $/$9$C$C$E$KK!-8->->-@VzsEEDUU
VVVs   
A,#A,c                    | j                   | j                  | j                  | j                  | j                  | j
                  | j                  | j                  | j                  | j                  | j                  | j                  dS )N)r'   r&   r*   r+   r(   r)   r   r   r,   r-   r.   r/   )r   r   r   r   r   r   r   r   r   r   r   r   r%   s    r1   r6   zCredentials.constructor_args   sl    !00"22!00ZZkk**ll $ 6 6#44
 	
r2   c                     | j                   S )z/Optional[str]: The OAuth 2.0 permission scopes.)r   r@   s    r1   r-   zCredentials.scopes   s     ||r2   c                      y)zw False: OAuth 2.0 credentials have their scopes set when
        the initial token is requested and can not be changed.F r@   s    r1   requires_scopeszCredentials.requires_scopes   s     r2   c                     | j                   S )z'Optional[str]: The OAuth 2.0 client ID.)r   r@   s    r1   r(   zCredentials.client_id        r2   c                     | j                   S )z+Optional[str]: The OAuth 2.0 client secret.)r   r@   s    r1   r)   zCredentials.client_secret        """r2   c                     | j                   S )zOptional[str]: The STS audience which contains the resource name for the
            workforce pool and the provider identifier in that pool.)r   r@   s    r1   r'   zCredentials.audience   s     ~~r2   c                     | j                   S )z+Optional[str]: The OAuth 2.0 refresh token.)r   r@   s    r1   r&   zCredentials.refresh_token   rH   r2   c                     | j                   S )z;Optional[str]: The STS token exchange endpoint for refresh.)r   r@   s    r1   r*   zCredentials.token_url   rF   r2   c                     | j                   S )z/Optional[str]: The STS endpoint for token info.)r   r@   s    r1   r+   zCredentials.token_info_url   s     ###r2   c                     | j                   S )z5Optional[str]: The STS endpoint for token revocation.)r   r@   s    r1   r,   zCredentials.revoke_url   s     r2   c                      y)z0 True: This credential always represents a user.TrC   r@   s    r1   is_userzCredentials.is_user   s     r2   c                 p    t        | j                  | j                  | j                  | j                  f      S N)allr   r   r   r   r@   s    r1   r   zCredentials.can_refresh   s/      $//4??DDWDWX
 	
r2   c                      y)a  Retrieves the project ID corresponding to the workload identity or workforce pool.
        For workforce pool credentials, it returns the project ID corresponding to
        the workforce_pool_user_project.

        When not determinable, None is returned.

        Args:
            request (google.auth.transport.requests.Request): Request object.
                Unused here, but passed from _default.default().

        Return:
          str: project ID is not determinable for this credential type so it returns None
        NrC   r%   requests     r1   get_project_idzCredentials.get_project_id   s     r2   c                     |r|ng }t        j                  | j                  j                         D ci c]  \  }}||vs|| c}}      S c c}}w )a  Utility function that creates a JSON representation of this
        credential.
        Args:
            strip (Sequence[str]): Optional list of members to exclude from the
                                   generated JSON.
        Returns:
            str: A JSON representation of this instance. When converted into
            a dictionary, it can be passed to from_info()
            to create a new instance.
        )jsondumpsr>   r:   )r%   stripkvs       r1   to_jsonzCredentials.to_json   sC     Bzzdiioo.?RFQ1E>1a4RSSRs   A
 A
c                 8   | j                   st        j                  d      t        j                         }| j                  |      }|j                  d      | _        t        j                  |j                  d            }||z   | _
        d|v r|d   | _        yy)a  Refreshes the access token.

        Args:
            request (google.auth.transport.Request): The object used to make
                HTTP requests.

        Raises:
            google.auth.exceptions.RefreshError: If the credentials could
                not be refreshed.
        zThe credentials do not contain the necessary fields need to refresh the access token. You must specify refresh_token, token_url, client_id, and client_secret.access_token
expires_in)secondsr&   N)r   r   RefreshErrorr   utcnow_make_sts_requestgetr   datetime	timedeltar   r   )r%   rU   nowresponse_datalifetimes        r1   refreshzCredentials.refresh  s     ));  oo..w7"&&~6
%%m.?.?.MNHnm+"/"@D ,r2   c                 N    | j                   j                  || j                        S rQ   )r$   r&   r   rT   s     r1   rd   zCredentials._make_sts_request#  s!    --gt7J7JKKr2   c                 :    | j                   r| j                   ddS y )Nz,external account authorized user credentials)credential_sourcecredential_type)r   r@   s    r1   get_cred_infozCredentials.get_cred_info&  s&    %)%9%9#Q  r2   c                 l    | j                         } | j                  di |}| j                  |_        |S )NrC   )r6   r0   r   )r%   kwargscreds      r1   
_make_copyzCredentials._make_copy/  s6    &&(t~~''#33r2   c                 4    | j                         }||_        |S rQ   )rt   r   )r%   r.   rs   s      r1   with_quota_projectzCredentials.with_quota_project5  s     !1r2   c                 4    | j                         }||_        |S rQ   )rt   r   )r%   	token_urirs   s      r1   with_token_urizCredentials.with_token_uri;  s     #r2   c                 4    | j                         }||_        |S rQ   )rt   r   )r%   r/   rs   s      r1   with_universe_domainz Credentials.with_universe_domainA  s      /r2   c                 <   |j                  d      }|rAt        j                  j                  |j                  d      j	                  d      d   d      } | d|j                  d      |j                  d      |j                  d      |j                  d	      |j                  d
      |j                  d      |j                  d      ||j                  d      |j                  d      |j                  d      |j                  dt
        j                        d|S )a  Creates a Credentials instance from parsed external account info.

        Args:
            info (Mapping[str, str]): The external account info in Google
                format.
            kwargs: Additional arguments to pass to the constructor.

        Returns:
            google.auth.external_account_authorized_user.Credentials: The
                constructed credentials.

        Raises:
            ValueError: For invalid parameters.
        r   r5   .r   z%Y-%m-%dT%H:%M:%Sr'   r&   r*   r+   r(   r)   r   r,   r.   r-   r/   )r'   r&   r*   r+   r(   r)   r   r   r,   r.   r-   r/   rC   )re   rf   strptimerstripsplitr   r   )clsr>   rr   r   s       r1   	from_infozCredentials.from_infoG  s      (#&&//c"((-a02EF  
XXj)((?3hh{+88$45hh{+((?3((7#xx-!XX&8988H% HH!;#F#F
 
 	
r2   c                     t        j                  |dd      5 }t        j                  |      } | j                  |fi |cddd       S # 1 sw Y   yxY w)al  Creates a Credentials instance from an external account json file.

        Args:
            filename (str): The path to the external account json file.
            kwargs: Additional arguments to pass to the constructor.

        Returns:
            google.auth.external_account_authorized_user.Credentials: The
                constructed credentials.
        rzutf-8)encodingN)ioopenrX   loadr   )r   filenamerr   	json_filedatas        r1   	from_filezCredentials.from_filen  sL     WWXsW5 	199Y'D 3==00	1 	1 	1s   (AArQ   )(__name__
__module____qualname____doc__r   r   r   propertyr>   r6   r-   rD   r(   r)   r'   r&   r*   r+   r,   rO   r   rV   r]   rk   rd   r   copy_docstringr
   rp   rt   CredentialsWithQuotaProjectrv   CredentialsWithTokenUriry   CredentialsWithUniverseDomainr{   classmethodr   r   __classcell__)r0   s   @r1   r
   r
   1   s   
	 #;;HJT W W"
     
   # #  
 # #   $ $       
 

"TA:L X[445 6 X[DDE F
 X[@@A B
 X[FFG H
 $
 $
L 1 1r2   r
   )r   rf   r   rX   google.authr   r   r   google.oauth2r   r   r8   r   ReadOnlyScopedr   r
   rC   r2   r1   <module>r      sQ   *  	    # "  .P +K1++''K1r2   