| Server IP : 138.197.176.125 / Your IP : 216.73.217.54 Web Server : Apache/2.4.41 (Ubuntu) System : Linux SuiteCRM-8 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 User : root ( 0) PHP Version : 8.3.19 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /lib/python3/dist-packages/sos/policies/auth/__pycache__/ |
Upload File : |
U
-�_g� � @ sz d dl Z zd dlZdZW n ek
r0 dZY nX d dlZd dlmZmZ d dlmZ dZ dZ
e �d�ZG d d
� d
�Z
dS )� NTF)�datetime� timedelta)�TIMEOUT_DEFAULTz sos-toolsz,urn:ietf:params:oauth:grant-type:device_codeZsosc @ sZ e Zd ZdZdd� Zdd� Zdd� Zdd � Zd
d� Zdd
� Z dd� Z
dd� Zddd�ZdS )�DeviceAuthorizationClassz$
Device Authorization Class
c C s* d | _ d | _d | _|| _|| _| �� d S )N)�
_access_token�_access_expires_at�&_DeviceAuthorizationClass__device_code�client_identifier_url�token_endpoint�_use_device_code_grant)�selfr r
� r
�</usr/lib/python3/dist-packages/sos/policies/auth/__init__.py�__init__! s z!DeviceAuthorizationClass.__init__c C s$ | � � td| 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 r
r
r r + s
�z/DeviceAuthorizationClass._use_device_code_grantc
C s� dt � �}ddi}tstd��zdtj| j||td�}|�� |�� }|� d�| _
|� d�| _|� d�| _|� d �| _
|� d
�| _W n< tjk
r� } zt�d|j� d|� ���W 5 d
}~X Y nX d
S )zm
Initialize new Device Authorization Grant attempt by
requesting a new device code.
z
client_id=zcontent-typez!application/x-www-form-urlencoded�Rpython3-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 r Zraise_for_status�json�getZ
_user_codeZ_verification_uri� _intervalr r Z HTTPError�status_code)r r r �resZresponse�er
r
r r 9 s,
��
z-DeviceAuthorizationClass._request_device_codec
C s� t t| jd�}tstd��| jdkr�t�| j� ztt j
| j|td�}|j
}|dkrjt�d� | �|�� � |dkr~t||j��|dkr�|�� d d
kr�t||j��W q t jjk
r� } zt�d|� �� W 5 d}~X Y qX qdS )z�
Continuously poll OIDC token endpoint until the user is successfully
authenticated or an error occurs.
)�
grant_type� client_idr r N�r r �� z$The SSO authentication is successful)r) � r* �error)Zauthorization_pendingZ slow_downz)Error was found while posting a request: )�GRANT_TYPE_DEVICE_CODEr r r r r �time�sleepr"