HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux ip-172-26-0-120 6.17.0-1009-aws #9~24.04.2-Ubuntu SMP Fri Mar 6 23:50:29 UTC 2026 x86_64
User: ubuntu (1000)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/sos/policies/auth/__pycache__/__init__.cpython-312.pyc
�

O6ufT ���ddlZ	ddlZdZddlZddlmZmZdZdZejd�Z
Gd�d	�Zy#e$rdZY�6wxYw)
�NTF)�datetime�	timedeltaz	sos-toolsz,urn:ietf:params:oauth:grant-type:device_code�sosc�H�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zdd�Zy
)
�DeviceAuthorizationClassz$
    Device Authorization Class
    c�j�d|_d|_d|_||_||_|j�y�N)�
_access_token�_access_expires_at�&_DeviceAuthorizationClass__device_code�client_identifier_url�token_endpoint�_use_device_code_grant)�selfr
rs   �</usr/lib/python3/dist-packages/sos/policies/auth/__init__.py�__init__z!DeviceAuthorizationClass.__init__s6��!���"&���!���%:��"�,����#�#�%�c�t�|j�td|j���|j�y)zv
        Start the device auth flow. In the future we will
        store the tokens in an in-memory keyring.

        z<Please visit the following URL to authenticate this device: N)�_request_device_code�print�_verification_uri_complete�poll_for_auth_completion�rs rrz/DeviceAuthorizationClass._use_device_code_grant)s<��	
�!�!�#�
�
��7�7�8�
:�	
�	
�%�%�'rc�"�dt��}ddi}tstd��	tj|j
||��}|j
�|j�}|jd�|_	|jd�|_
|jd�|_|jd	�|_|jd
�|_
y
#tj$r*}tjdj�d|����d
}~wwxYw)zm
        Initialize new Device Authorization Grant attempt by
        requesting a new device code.

        z
client_id=zcontent-typez!application/x-www-form-urlencoded�Rpython3-requests is not installed and is required for obtaining device auth token.)�data�headers�	user_code�verification_uri�interval�device_code�verification_uri_completezNHTTP request failed while attempting to acquire the tokens.Error returned was � N)�DEVICE_AUTH_CLIENT_ID�REQUESTS_LOADED�	Exception�requests�postr
�raise_for_status�json�get�
_user_code�_verification_uri�	_intervalrr�	HTTPError�status_code)rrr�res�response�es      rrz-DeviceAuthorizationClass._request_device_code7s���1�2�3��!�#F�G����@�A�
A�	-��-�-��*�*���!�C�
� � �"��x�x�z�H�&�l�l�;�7�D�O�%-�\�\�2D�%E�D�"�%�\�\�*�5�D�N�!)���m�!<�D��.6�l�l�+�/-�D�+���!�!�	-��$�$�&;�;>�?�?�:K�1�()�s�&,�-�
-��	-�s�B0C�D�$%D	�	Dc��tt|jd�}tst	d��|j
��t
j|j�	tj|j|��}|j}|dk(r4tjd�|j|j!��|dvrt	||j"��|dk(r+|j!�d	d
vrt	||j"��|j
���yy#tj$j&$r"}tj)d|���Yd}~�Id}~wwxYw)z�
        Continuously poll OIDC token endpoint until the user is successfully
        authenticated or an error occurs.

        )�
grant_type�	client_idr!rN�r��z$The SSO authentication is successful)r8�r9�error)�authorization_pending�	slow_downz)Error was found while posting a request: )�GRANT_TYPE_DEVICE_CODEr$rr%r&r
�time�sleepr.r'r(rr0�logger�info�_set_token_datar*�text�
exceptions�RequestExceptionr:)r�
token_data�check_auth_completionr0r3s     rrz1DeviceAuthorizationClass.poll_for_auth_completionUsA��%;�#8�%)�%7�%7�9�
���@�A�
A�� � �(��J�J�t�~�~�&�
N�(0�
�
�d�6I�6I�;E�)G�%�4�?�?���#�%��K�K� F�G��(�(�)>�)C�)C�)E�F��j�0�#�K�1F�1K�1K�L�L��#�%�)�.�.�0��9�>�?�#�K�1F�1K�1K�L�L�!� � �(��"�&�&�7�7�
N����H���L�M�M��
N�s�B0D�E�2E�Ec��|jd�|_tj�t	|jd���z|_|jd�|_|jd�|_|jdk(rtj|_	ytj�t	|j��z|_	y)a@
        Set the class attributes as per the input token_data received.
        In the future we will persist the token data in a local,
        in-memory keyring, to avoid visting the browser frequently.
        :param token_data: Token data containing access_token, refresh_token
        and their expiry etc.
        �access_token�
expires_in��seconds�
refresh_token�refresh_expires_inrN)
r+r
r�utcnowrr�_refresh_token�_refresh_expires_in�max�_refresh_expires_at)rrFs  rrBz(DeviceAuthorizationClass._set_token_datavs���(�^�^�N�;���"*�/�/�"3��j�n�n�\�:�;�#<���(�n�n�_�=���#-�>�>�2F�#G�� ��#�#�q�(�'/�|�|�D�$�'/���'8��$�":�":�;�(<�D�$rc���|j�r|jS|j�r|j�|jS|j	�|jS)zt
        Get the valid access_token at any given time.
        :return: Access_token
        :rtype: string
        )�is_access_token_validr
�is_refresh_token_valid�_use_refresh_token_grantrrs r�get_access_tokenz)DeviceAuthorizationClass.get_access_token�sX���%�%�'��%�%�%��*�*�,��-�-�/��)�)�)��+�+�-��)�)�)rc��|jxr<|jxr.|jtd��z
tj�kDS)z�
        Check the validity of access_token. We are considering it invalid 180
        sec. prior to it's exact expiry time.
        :return: True/False

        �rK)r
rrrrOrs rrUz.DeviceAuthorizationClass.is_access_token_valid�sF���!�!��d�&=�&=���#�#�i��&<�<��O�O��
�	rc��|jxr<|jxr.|jtd��z
tj�kDS)z�
        Check the validity of refresh_token. We are considering it invalid
        180 sec. prior to it's exact expiry time.

        :return: True/False

        rZrK)rPrSrrrOrs rrVz/DeviceAuthorizationClass.is_refresh_token_valid�sF���"�"��t�'?�'?���$�$�y��'=�=��O�O��
�	rNc�$�tstd��td|s|jn|d�}t	j
|j|��}|jdk(r |j|j��y|jdk(r]d|j�dvrHtjd	|j�d
|j�d�d��|j�ytd|j�d
|j�d����)z�
        Fetch the new access_token and refresh_token using the existing
        refresh_token and persist it.
        :param refresh_token: optional param for refresh_token

        rrM)r6r5rMr7r8r9�invalidr:zAProblem while fetching the new tokens from refresh token grant - r#z%. New Device code will be requested !zcSomething went wrong while using the Refresh token grant for fetching tokens: Returned status code z and error N)
r%r&r$rPr'r(rr0rBr*r@�warningr)rrM�refresh_token_data�refresh_token_ress    rrWz1DeviceAuthorizationClass._use_refresh_token_grant�s3����@�A�
A�+@�,;�+�04�/B�/B�1>�@��
%�M�M�$�*=�*=�/A�C���(�(�C�/�� � �!2�!7�!7�!9�:�
�
*�
*�c�
1�i�!�&�&�(��1�72��N�N�-�->�-J�-J�,K�1�/�4�4�6�w�?�@�AB�B�
C�
�'�'�)��)�):�)F�)F�(G��/�4�4�6�w�?�@�B�C�
Crr	)
�__name__�
__module__�__qualname__�__doc__rrrrrBrXrUrVrW�rrrrs7���&�(�-�<N�B<�&*� 	�
�!Crr)�loggingr'r%�ImportErrorr>rrr$r=�	getLoggerr@rrerr�<module>risa������O��(�#��G��	��	�	�5�	!��wC�wC�����O��s�9�A�A