NineSec Team Shell
Server IP : 184.107.3.203  /  Your IP : 216.73.216.51
Web Server : Apache
System : Linux dedicated2.avenfashion.com.ph 4.18.0-553.40.1.el8_10.x86_64 #1 SMP Mon Feb 10 12:11:18 EST 2025 x86_64
User : adminteladeoro ( 1015)
PHP Version : 8.2.28
Disable Function : exec,passthru,shell_exec,system
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /usr/lib/python3.6/site-packages/sos/policies/auth/__pycache__/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : //usr/lib/python3.6/site-packages/sos/policies/auth/__pycache__/__init__.cpython-36.pyc
3

~�g,!�@s~ddlZyddlZdZWnek
r0dZYnXddlZddlmZmZmZddlm	Z	dZ
dZejd�Z
Gd	d
�d
�ZdS)�NTF)�datetime�	timedelta�timezone)�TIMEOUT_DEFAULTz	sos-toolsz,urn:ietf:params:oauth:grant-type:device_codeZsosc@sZeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zddd�ZdS)�DeviceAuthorizationClassz$
    Device Authorization Class
    cCs*d|_d|_d|_||_||_|j�dS)N)�
_access_token�_access_expires_at�&_DeviceAuthorizationClass__device_code�client_identifier_url�token_endpoint�_use_device_code_grant)�selfr
r�r�/usr/lib/python3.6/__init__.py�__init__!sz!DeviceAuthorizationClass.__init__cCs$|j�td|j���|j�dS)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)r
rrrr+sz/DeviceAuthorizationClass._use_device_code_grantcCs�dt��}ddi}tstd��ydtj|j||td�}|j�|j�}|j	d�|_
|j	d�|_|j	d�|_|j	d	�|_
|j	d
�|_Wn<tjk
r�}ztjd|j�d|����WYd
d
}~XnXd
S)zm
        Initialize new Device Authorization Grant attempt by
        requesting a new device code.

        z
client_id=zcontent-typez!application/x-www-form-urlencodedzRpython3-requests is not installed and is required for obtaining device auth token.)�data�headers�timeoutZ	user_codeZverification_uriZinterval�device_codeZverification_uri_completezNHTTP request failed while attempting to acquire the tokens.Error returned was � N)�DEVICE_AUTH_CLIENT_ID�REQUESTS_LOADED�	Exception�requests�postr
rZraise_for_status�json�getZ
_user_codeZ_verification_uri�	_intervalr	rZ	HTTPError�status_code)r
rr�resZresponse�errrr9s(
z-DeviceAuthorizationClass._request_device_codecCs�tt|jd�}tstd��x�|jdkr�tj|j�ytt	j
|j|td�}|j
}|dkrltjd�|j|j��|dkr�t||j��|dkr�|j�dd
kr�t||j��Wqt	jjk
r�}ztjd|���WYdd}~XqXqWdS)z�
        Continuously poll OIDC token endpoint until the user is successfully
        authenticated or an error occurs.

        )�
grant_type�	client_idrzRpython3-requests is not installed and is required for obtaining device auth token.N)rr��z$The SSO authentication is successful��error�authorization_pending�	slow_downz)Error was found while posting a request: )r'r()r*r+)�GRANT_TYPE_DEVICE_CODErr	rrr�timeZsleepr!rrrrr"�logger�info�_set_token_datar�text�
exceptionsZRequestExceptionr))r
�
token_dataZcheck_auth_completionr"r$rrrrXs.


z1DeviceAuthorizationClass.poll_for_auth_completioncCst|jd�|_tjtj�t|jd�d�|_|jd�|_|jd�|_	|j	dkrVtj
|_ntjtj�t|j	d�|_dS)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.
        Zaccess_tokenZ
expires_in)�seconds�
refresh_tokenZrefresh_expires_inrN)r rr�nowr�utcrr�_refresh_tokenZ_refresh_expires_in�max�_refresh_expires_at)r
r3rrrr0zs



z(DeviceAuthorizationClass._set_token_datacCs2|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_grantr)r
rrr�get_access_token�sz)DeviceAuthorizationClass.get_access_tokencCs(|jo&|jo&|jtdd�tjtj�kS)z�
        Check the validity of access_token. We are considering it invalid 180
        sec. prior to it's exact expiry time.
        :return: True/False

        �)r4)rrrrr6rr7)r
rrrr;�sz.DeviceAuthorizationClass.is_access_token_validcCs(|jo&|jo&|jtdd�tjtj�kS)z�
        Check the validity of refresh_token. We are considering it invalid
        180 sec. prior to it's exact expiry time.

        :return: True/False

        r?)r4)r8r:rrr6rr7)r
rrrr<�sz/DeviceAuthorizationClass.is_refresh_token_validNcCs�tstd��td|s|jn|d�}tj|j|td�}|jdkrN|j	|j
��nd|jdkr�d|j
�dkr�tjd	|j�d
|j
�d�d��|j
�ntd|j�d
|j
�d����dS)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

        zRpython3-requests is not installed and is required for obtaining device auth token.r5)r&r%r5)rrr'i�Zinvalidr)zAProblem while fetching the new tokens from refresh token grant - rz%. 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)rrrr8rrrrr"r0rr.Zwarningr)r
r5Zrefresh_token_dataZrefresh_token_resrrrr=�s 
"
z1DeviceAuthorizationClass._use_refresh_token_grant)N)
�__name__�
__module__�__qualname__�__doc__rrrrr0r>r;r<r=rrrrrs
"r)Zloggingrr�ImportErrorr-rrrZ
sos.utilitiesrrr,Z	getLoggerr.rrrrr�<module>s



NineSec Team - 2022