
    gI                     b   d Z ddlZddlmZ ddlZddlmZ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      Z G d de      Z G d de      Z G d de      Z G d de      Z G d dej(                        Z G d de      ZddZ G d dej(                        Z G d de      Zy)zInterfaces for credentials.    N)Enum)_helpersenvironment_vars)
exceptions)metrics)_BaseCredentials)RefreshThreadManagerzgoogleapis.comc                        e Zd ZdZ fdZed        Zed        Zed        Zed        Z	ed        Z
d Zej                  d	        Zd
 ZddZd Zd Zd Zd Z xZS )CredentialsaQ  Base class for all credentials.

    All credentials have a :attr:`token` that is used for authentication and
    may also optionally set an :attr:`expiry` to indicate when the token will
    no longer be valid.

    Most credentials will be :attr:`invalid` until :meth:`refresh` is called.
    Credentials can do this automatically before the first HTTP request in
    :meth:`before_request`.

    Although the token and expiration will change as the credentials are
    :meth:`refreshed <refresh>` and used, credentials should be considered
    immutable. Various credentials will accept configuration such as private
    keys, scopes, and other options. These options are not changeable after
    construction. Some classes will provide mechanisms to copy the credentials
    with modifications such as :meth:`ScopedCredentials.with_scopes`.
    c                     t         t        |           d | _        	 d | _        	 d | _        	 t        | _        	 d| _        t               | _
        y NF)superr   __init__expiry_quota_project_id_trust_boundaryDEFAULT_UNIVERSE_DOMAIN_universe_domain_use_non_blocking_refreshr	   _refresh_workerself	__class__s    t/var/www/html/FastMealFinder_FlaskServer-InitialRelease/venv/lib/python3.12/site-packages/google/auth/credentials.pyr   zCredentials.__init__2   sY    k4)+	B!%K#	 !8	 */&35    c                     | j                   sy| j                   t        j                  z
  }t        j                         |k\  S )a(  Checks if the credentials are expired.

        Note that credentials can be invalid but not expired because
        Credentials with :attr:`expiry` set to None is considered to never
        expire.

        .. deprecated:: v2.24.0
          Prefer checking :attr:`token_state` instead.
        F)r   r   REFRESH_THRESHOLDutcnow)r   skewed_expirys     r   expiredzCredentials.expiredE   s6     {{ h&@&@@ M11r   c                 <    | j                   duxr | j                   S )zChecks the validity of the credentials.

        This is True if the credentials have a :attr:`token` and the token
        is not :attr:`expired`.

        .. deprecated:: v2.24.0
          Prefer checking :attr:`token_state` instead.
        N)tokenr    r   s    r   validzCredentials.validW   s     zz%:dll*::r   c                    | j                   t        j                  S | j                  t        j                  S t        j                         | j                  k\  }|rt        j                  S t        j                         | j                  t
        j                  z
  k\  }|rt        j                  S t        j                  S )z(
        See `:obj:`TokenState`
        )	r"   
TokenStateINVALIDr   FRESHr   r   r   STALE)r   r    is_stales      r   token_statezCredentials.token_statec   s    
 ::%%% ;;###//#t{{2%%%??$x7Q7Q)QR###r   c                     | j                   S )z.Project to use for quota and billing purposes.)r   r#   s    r   quota_project_idzCredentials.quota_project_idy   s     %%%r   c                     | j                   S )zThe universe domain value.)r   r#   s    r   universe_domainzCredentials.universe_domain~   s     $$$r   c                      y)zThe credential information JSON.

        The credential information will be added to auth related error messages
        by client library.

        Returns:
            Mapping[str, str]: The credential information JSON.
        N r#   s    r   get_cred_infozCredentials.get_cred_info   s     r   c                     t        d      )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.
        zRefresh must be implementedNotImplementedErrorr   requests     r   refreshzCredentials.refresh   s     ""?@@r   c                      y)a  The x-goog-api-client header for token usage metric.

        This header will be added to the API service requests in before_request
        method. For example, "cred-type/sa-jwt" means service account self
        signed jwt access token is used in the API service request
        authorization header. Children credentials classes need to override
        this method to provide the header value, if the token usage metric is
        needed.

        Returns:
            str: The x-goog-api-client header value.
        Nr1   r#   s    r   _metric_header_for_usagez$Credentials._metric_header_for_usage   s     r   c                     | j                  ||       	 | j                  | j                  d   |d<   | j                  r| j                  |d<   yy)zApply the token to the authentication header.

        Args:
            headers (Mapping): The HTTP request headers.
            token (Optional[str]): If specified, overrides the current access
                token.
        )r"   Nencoded_locationszx-allowed-locationszx-goog-user-project)_applyr   r-   r   headersr"   s      r   applyzCredentials.apply   s]     	G5)	 +-1-A-ABU-VG)*  -1-B-BG)* !r   c                 @    | j                   s| j                  |       y y N)r$   r8   r6   s     r   _blocking_refreshzCredentials._blocking_refresh   s    zzLL! r   c                    d}| j                   t        j                  k(  r| j                  j	                  | |       }| j                   t        j
                  k(  s|r,| j                  |       | j                  j                          y y r   )r+   r&   r)   r   start_refreshr'   r8   clear_error)r   r7   use_blocking_refresh_fallbacks      r   _non_blocking_refreshz!Credentials._non_blocking_refresh   s|    (-%z///040D0D0R0Rg1 -) z1115RLL!   ,,. 6Sr   c                     | j                   r| j                  |       n| j                  |       t        j                  || j                                | j                  |       y)a  Performs credential-specific before request logic.

        Refreshes the credentials if necessary, then calls :meth:`apply` to
        apply the token to the authentication header.

        Args:
            request (google.auth.transport.Request): The object used to make
                HTTP requests.
            method (str): The request's HTTP method or the RPC method being
                invoked.
            url (str): The request's URI or the RPC service's URI.
            headers (Mapping): The request's headers.
        N)r   rH   rC   r   add_metric_headerr:   r@   r   r7   methodurlr?   s        r   before_requestzCredentials.before_request   sN    " ))&&w/""7+!!'4+H+H+JK

7r   c                     d| _         y )NT)r   r#   s    r   with_non_blocking_refreshz%Credentials.with_non_blocking_refresh   s
    )-&r   rB   )__name__
__module____qualname____doc__r   propertyr    r$   r+   r-   r/   r2   abcabstractmethodr8   r:   r@   rC   rH   rN   rP   __classcell__r   s   @r   r   r      s    $6& 2 2" 	; 	;    * & & % %	 	A AC6"/2.r   r   c                       e Zd ZdZd Zd Zy)CredentialsWithQuotaProjectzGAbstract base for credentials supporting ``with_quota_project`` factoryc                     t        d      )a  Returns a copy of these credentials with a modified quota project.

        Args:
            quota_project_id (str): The project to use for quota and
                billing purposes

        Returns:
            google.auth.credentials.Credentials: A new credentials instance.
        z/This credential does not support quota project.r4   )r   r-   s     r   with_quota_projectz.CredentialsWithQuotaProject.with_quota_project   s     ""STTr   c                     t         j                  j                  t        j                        }|r| j                  |      S | S rB   )osenvirongetr   GOOGLE_CLOUD_QUOTA_PROJECTr]   )r   quota_from_envs     r   #with_quota_project_from_environmentz?CredentialsWithQuotaProject.with_quota_project_from_environment  s4    (8(S(ST**>::r   N)rQ   rR   rS   rT   r]   rd   r1   r   r   r[   r[      s    Q
Ur   r[   c                       e Zd ZdZd Zy)CredentialsWithTokenUrizCAbstract base for credentials supporting ``with_token_uri`` factoryc                     t        d      )a   Returns a copy of these credentials with a modified token uri.

        Args:
            token_uri (str): The uri to use for fetching/exchanging tokens

        Returns:
            google.auth.credentials.Credentials: A new credentials instance.
        z'This credential does not use token uri.r4   )r   	token_uris     r   with_token_uriz&CredentialsWithTokenUri.with_token_uri  s     ""KLLr   N)rQ   rR   rS   rT   ri   r1   r   r   rf   rf     s    M	Mr   rf   c                       e Zd ZdZd Zy)CredentialsWithUniverseDomainzIAbstract base for credentials supporting ``with_universe_domain`` factoryc                     t        d      )zReturns a copy of these credentials with a modified universe domain.

        Args:
            universe_domain (str): The universe domain to use

        Returns:
            google.auth.credentials.Credentials: A new credentials instance.
        z6This credential does not support with_universe_domain.r4   )r   r/   s     r   with_universe_domainz2CredentialsWithUniverseDomain.with_universe_domain   s     "D
 	
r   N)rQ   rR   rS   rT   rm   r1   r   r   rk   rk     s
    S
r   rk   c                   D    e Zd ZdZed        Zed        Zd ZddZd Z	y)	AnonymousCredentialszCredentials that do not provide any authentication information.

    These are useful in the case of services that support anonymous access or
    local service emulators that do not use credentials.
    c                      y)z4Returns `False`, anonymous credentials never expire.Fr1   r#   s    r   r    zAnonymousCredentials.expired5  s     r   c                      y)z7Returns `True`, anonymous credentials are always valid.Tr1   r#   s    r   r$   zAnonymousCredentials.valid:  s     r   c                 ,    t        j                  d      )zVRaises :class:``InvalidOperation``, anonymous credentials cannot be
        refreshed.z*Anonymous credentials cannot be refreshed.)r   InvalidOperationr6   s     r   r8   zAnonymousCredentials.refresh?  s     ))*VWWr   Nc                 2    |t        j                  d      y)zAnonymous credentials do nothing to the request.

        The optional ``token`` argument is not supported.

        Raises:
            google.auth.exceptions.InvalidValue: If a token was specified.
        Nz+Anonymous credentials don't support tokens.)r   InvalidValuer>   s      r   r@   zAnonymousCredentials.applyD  s!     ))*WXX r   c                      y)z0Anonymous credentials do nothing to the request.Nr1   rK   s        r   rN   z#AnonymousCredentials.before_requestO  s    r   rB   )
rQ   rR   rS   rT   rU   r    r$   r8   r@   rN   r1   r   r   ro   ro   .  s@        X
	Y?r   ro   c                   l     e Zd ZdZ fdZed        Zed        Zej                  d        Z
d Z xZS )ReadOnlyScopeda+  Interface for credentials whose scopes can be queried.

    OAuth 2.0-based credentials allow limiting access using scopes as described
    in `RFC6749 Section 3.3`_.
    If a credential class implements this interface then the credentials either
    use scopes in their implementation.

    Some credentials require scopes in order to obtain a token. You can check
    if scoping is necessary with :attr:`requires_scopes`::

        if credentials.requires_scopes:
            # Scoping is required.
            credentials = credentials.with_scopes(scopes=['one', 'two'])

    Credentials that require scopes must either be constructed with scopes::

        credentials = SomeScopedCredentials(scopes=['one', 'two'])

    Or must copy an existing instance using :meth:`with_scopes`::

        scoped_credentials = credentials.with_scopes(scopes=['one', 'two'])

    Some credentials have scopes but do not allow or require scopes to be set,
    these credentials can be used as-is.

    .. _RFC6749 Section 3.3: https://tools.ietf.org/html/rfc6749#section-3.3
    c                 F    t         t        |           d | _        d | _        y rB   )r   rx   r   _scopes_default_scopesr   s    r   r   zReadOnlyScoped.__init__p  s    nd,.#r   c                     | j                   S )z6Sequence[str]: the credentials' current set of scopes.)rz   r#   s    r   scopeszReadOnlyScoped.scopesu  s     ||r   c                     | j                   S )z>Sequence[str]: the credentials' current set of default scopes.)r{   r#   s    r   default_scopeszReadOnlyScoped.default_scopesz  s     ###r   c                      y)zLTrue if these credentials require scopes to obtain an access token.
        Fr1   r#   s    r   requires_scopeszReadOnlyScoped.requires_scopes  s     r   c                     | j                   | j                   n| j                  }t        |      j                  t        |xs g             S )a_  Checks if the credentials have the given scopes.

        .. warning: This method is not guaranteed to be accurate if the
            credentials are :attr:`~Credentials.invalid`.

        Args:
            scopes (Sequence[str]): The list of scopes to check.

        Returns:
            bool: True if the credentials have the given scopes.
        )rz   r{   setissubset)r   r}   credential_scopess      r   
has_scopeszReadOnlyScoped.has_scopes  sC     !LL4DLL$:N:N 	 6{##C(9(?R$@AAr   )rQ   rR   rS   rT   r   rU   r}   r   rV   abstractpropertyr   r   rX   rY   s   @r   rx   rx   S  sU    8$
   $ $ 	 
Br   rx   )	metaclassc                   6    e Zd ZdZej
                  dd       Zy)Scopeda5  Interface for credentials whose scopes can be replaced while copying.

    OAuth 2.0-based credentials allow limiting access using scopes as described
    in `RFC6749 Section 3.3`_.
    If a credential class implements this interface then the credentials either
    use scopes in their implementation.

    Some credentials require scopes in order to obtain a token. You can check
    if scoping is necessary with :attr:`requires_scopes`::

        if credentials.requires_scopes:
            # Scoping is required.
            credentials = credentials.create_scoped(['one', 'two'])

    Credentials that require scopes must either be constructed with scopes::

        credentials = SomeScopedCredentials(scopes=['one', 'two'])

    Or must copy an existing instance using :meth:`with_scopes`::

        scoped_credentials = credentials.with_scopes(scopes=['one', 'two'])

    Some credentials have scopes but do not allow or require scopes to be set,
    these credentials can be used as-is.

    .. _RFC6749 Section 3.3: https://tools.ietf.org/html/rfc6749#section-3.3
    Nc                     t        d      )a  Create a copy of these credentials with the specified scopes.

        Args:
            scopes (Sequence[str]): The list of scopes to attach to the
                current credentials.

        Raises:
            NotImplementedError: If the credentials' scopes can not be changed.
                This can be avoided by checking :attr:`requires_scopes` before
                calling this method.
        z$This class does not require scoping.r4   )r   r}   r   s      r   with_scopeszScoped.with_scopes  s     ""HIIr   rB   )rQ   rR   rS   rT   rV   rW   r   r1   r   r   r   r     s#    8 	J Jr   r   c                 d    t        | t              r| j                  r| j                  ||      S | S )a  Creates a copy of the credentials with scopes if scoping is required.

    This helper function is useful when you do not know (or care to know) the
    specific type of credentials you are using (such as when you use
    :func:`google.auth.default`). This function will call
    :meth:`Scoped.with_scopes` if the credentials are scoped credentials and if
    the credentials require scoping. Otherwise, it will return the credentials
    as-is.

    Args:
        credentials (google.auth.credentials.Credentials): The credentials to
            scope if necessary.
        scopes (Sequence[str]): The list of scopes to use.
        default_scopes (Sequence[str]): Default scopes passed by a
            Google client library. Use 'scopes' for user-defined scopes.

    Returns:
        google.auth.credentials.Credentials: Either a new set of scoped
            credentials, or the passed in credentials instance if no scoping
            was required.
    )r   )
isinstancer   r   r   )credentialsr}   r   s      r   with_scopes_if_requiredr     s2    , +v&;+F+F&&vn&MMr   c                   |    e Zd ZdZej
                  d        Zej                  d        Zej                  d        Z	y)SigningzCInterface for credentials that can cryptographically sign messages.c                     t        d      )zSigns the given message.

        Args:
            message (bytes): The message to sign.

        Returns:
            bytes: The message's cryptographic signature.
        zSign bytes must be implemented.r4   )r   messages     r   
sign_byteszSigning.sign_bytes  s     ""CDDr   c                     t        d      )z;Optional[str]: An email address that identifies the signer.z!Signer email must be implemented.r4   r#   s    r   signer_emailzSigning.signer_email  s    
 ""EFFr   c                     t        d      )z8google.auth.crypt.Signer: The signer used to sign bytes.zSigner must be implemented.r4   r#   s    r   signerzSigning.signer  s    
 ""?@@r   N)
rQ   rR   rS   rT   rV   rW   r   r   r   r   r1   r   r   r   r     sW    ME E 	G G 	A Ar   r   c                       e Zd ZdZdZdZdZy)r&   aJ  
    Tracks the state of a token.
    FRESH: The token is valid. It is not expired or close to expired, or the token has no expiry.
    STALE: The token is close to expired, and should be refreshed. The token can be used normally.
    INVALID: The token is expired or invalid. The token cannot be used for a normal operation.
             N)rQ   rR   rS   rT   r(   r)   r'   r1   r   r   r&   r&      s     EEGr   r&   rB   )rT   rV   enumr   r_   google.authr   r   r   r   google.auth._credentials_baser   google.auth._refresh_workerr	   r   r   r[   rf   rk   ro   ABCMetarx   r   r   r   r&   r1   r   r   <module>r      s     " 
  	 2 "  : <* V." V.r+ ,Mk M
K 
""?; "?JABs{{ ABH*J^ *JZ8A A@
 
r   