§
    9?ÄjÚ  ã                   óN   — d Z ddlmZ ddlZddlZddlZdZdZd„ Z	d
d„Z
	 d
d	„ZdS )zÖGet user credentials from interactive code environments.

This module contains helpers for getting user credentials from interactive
code environments installed on a development machine, such as Jupyter
notebooks.
é    )Úabsolute_importNÚ	localhostéd   c                 óÔ  — t          j        t          j        t          j        t          j        ¦  «        ¦  «        5 }	 |                     t          | f¦  «         |                     d¦  «         d}n# t          j        $ r d}Y nw xY wddd¦  «         n# 1 swxY w Y   |rFt          t          d¦  «        r1t          j        j                             t          j        d| ¦  «         }|S )a5  Check if a port is open on localhost.
    Based on StackOverflow answer: https://stackoverflow.com/a/43238489/101923
    Parameters
    ----------
    port : int
        A port to check on localhost.
    Returns
    -------
    is_open : bool
        True if a socket can be opened at the requested port.
    é   TFNÚAF_INET6z::1)Ú
contextlibÚclosingÚsocketÚAF_INETÚSOCK_STREAMÚbindÚ	LOCALHOSTÚlistenÚerrorÚhasattrÚgoogle_auth_oauthlibÚflowÚ_ExclusiveWSGIServerÚis_listener_presentr   )ÚportÚsockÚis_opens      úQC:\Projects\Historical\venv\Lib\site-packages\google_auth_oauthlib/interactive.pyÚis_port_openr   !   s#  € õ 
Ô	�FœM­&¬.½&Ô:LÑMÔMÑ	NÔ	Nð ÐRVð	Ø�IŠI•y $Ð'Ñ(Ô(Ð(Ø�KŠK˜‰NŒNˆNð ˆGˆGøõ Œ|ð 	ð 	ð 	ØˆGˆGˆGð	øøøð	ð ð ñ ô ð ð ð ð ð ð øøøð ð ð ð ð ð 
•7�6 :Ñ.Ô.ð 
å$Ô)Ô>×RÒRÝ” ¨ñô ð ð 	ð
 €Ns4   ¼B¾1A2Á/BÁ2BÂBÂBÂBÂBÂBé�  c                 ój   — |s
| t           z   }t          | |¦  «        D ]}t          |¦  «        r|c S ŒdS )aê  Find an open port between ``start`` and ``stop``.
    Parameters
    ----------
    start : Optional[int]
        Beginning of range of ports to try. Defaults to 8080.
    stop : Optional[int]
        End of range of ports to try (not including exactly equals ``stop``).
        This function tries 100 possible ports if no ``stop`` is specified.
    Returns
    -------
    Optional[int]
        ``None`` if no open port is found, otherwise an integer indicating an
        open port.
    N)ÚDEFAULT_PORTS_TO_TRYÚranger   )ÚstartÚstopr   s      r   Úfind_open_portr"   ?   sU   € ð ð ,ØÕ+Ñ+ˆå�e˜TÑ"Ô"ð ð ˆÝ˜ÑÔð 	ØˆKˆKˆKð	ð ˆ4ó    c                 óÜ   — d||dddœi}t           j        j                             || ¬¦  «        }t	          ||¬¦  «        }|st          d¦  «        ‚|                     t          |¬¦  «        S )	aÂ  Gets credentials associated with your Google user account.

    This function authenticates using your user credentials by going through
    the OAuth 2.0 flow. You'll open a browser window to authenticate to your
    Google account. The permissions it requests correspond to the scopes
    you've provided.

    To obtain the ``client_id`` and ``client_secret``, create an **OAuth
    client ID** with application type **Other** from the `Credentials page on
    the Google Developer's Console
    <https://console.developers.google.com/apis/credentials>`_. Learn more
    with the `Authenticating as an end user
    <https://cloud.google.com/docs/authentication/end-user>`_ guide.

    Args:
        scopes (Sequence[str]):
            A list of scopes to use when authenticating to Google APIs. See
            the `list of OAuth 2.0 scopes for Google APIs
            <https://developers.google.com/identity/protocols/googlescopes>`_.
        client_id (str):
            A string that identifies your application to Google APIs. Find
            this value in the `Credentials page on the Google Developer's
            Console
            <https://console.developers.google.com/apis/credentials>`_.
        client_secret (str):
            A string that verifies your application to Google APIs. Find this
            value in the `Credentials page on the Google Developer's Console
            <https://console.developers.google.com/apis/credentials>`_.
        minimum_port (int):
            Beginning of range of ports to try for redirect URI HTTP server.
            Defaults to 8080.
        maximum_port (Optional[int]):
            End of range of ports to try (not including exactly equals ``stop``).
            This function tries 100 possible ports if no ``stop`` is specified.

    Returns:
        google.oauth2.credentials.Credentials:
            The OAuth 2.0 credentials for the user.

    Examples:
        Get credentials for your user account and use them to run a query
        with BigQuery::

            import google_auth_oauthlib

            # TODO: Create a client ID for your project.
            client_id = "YOUR-CLIENT-ID.apps.googleusercontent.com"
            client_secret = "abc_ThIsIsAsEcReT"

            # TODO: Choose the needed scopes for your applications.
            scopes = ["https://www.googleapis.com/auth/cloud-platform"]

            credentials = google_auth_oauthlib.get_user_credentials(
                scopes, client_id, client_secret
            )

            # 1. Open the link.
            # 2. Authorize the application to have access to your account.
            # 3. Copy and paste the authorization code to the prompt.

            # Use the credentials to construct a client for Google APIs.
            from google.cloud import bigquery

            bigquery_client = bigquery.Client(
                credentials=credentials, project="your-project-id"
            )
            print(list(bigquery_client.query("SELECT 1").result()))
    Ú	installedz)https://accounts.google.com/o/oauth2/authz#https://oauth2.googleapis.com/token)Ú	client_idÚclient_secretÚauth_uriÚ	token_uri)Úscopes)r    r!   zCould not find open port.)Úhostr   )r   r   ÚInstalledAppFlowÚfrom_client_configr"   ÚConnectionErrorÚrun_local_serverr   )r*   r&   r'   Úminimum_portÚmaximum_portÚclient_configÚapp_flowr   s           r   Úget_user_credentialsr4   Y   s‘   € ðR 	Ø"Ø*ØCØ>ð	
ð 
ð€Mõ $Ô(Ô9×LÒLØ˜fð Mñ ô €Hõ  °<Ð@Ñ@Ô@€DØð ;ÝÐ9Ñ:Ô:Ð:à×$Ò$­)¸$Ð$Ñ?Ô?Ð?r#   )r   N)Ú__doc__Ú
__future__r   r	   r   Úgoogle_auth_oauthlib.flowr   r   r   r   r"   r4   © r#   r   ú<module>r9      s£   ððð ð 'Ð &Ð &Ð &Ð &Ð &à Ð Ð Ð Ø €€€à  Ð  Ð  Ð  à€	ØÐ ðð ð ð<ð ð ð ð6 GKðY@ð Y@ð Y@ð Y@ð Y@ð Y@r#   