+
    Û1j,!  ã                   ó¢   € ^ RI t  ^ RItRt^ RIt^ RIHtHtHt ^ RIH	t	 Rt
Rt] P                  ! R4      t ! R	 R
4      tR#   ] d    Rt LAi ; i)é    NTF)ÚdatetimeÚ	timedeltaÚtimezone)ÚTIMEOUT_DEFAULTz	sos-toolsz,urn:ietf:params:oauth:grant-type:device_codeÚsosc                   ó^   a € ] tR t^t o RtR tR tR tR tR t	R t
R tR	 tRR ltRtV tR
# )ÚDeviceAuthorizationClassz
Device Authorization Class
c                óh   € R V n         R V n        R V n        Wn        W n        V P                  4        R # ©N)Ú_access_tokenÚ_access_expires_atÚ&_DeviceAuthorizationClass__device_codeÚclient_identifier_urlÚtoken_endpointÚ_use_device_code_grant)Úselfr   r   s   &&&Ú</usr/lib/python3/dist-packages/sos/policies/auth/__init__.pyÚ__init__Ú!DeviceAuthorizationClass.__init__!   s2   € à!ˆÔØ"&ˆÔØ!ˆÔà%:Ô"Ø,ÔØ×#Ñ#Ö%ó    c                óv   € V P                  4        \        RV P                   24       V P                  4        R# )z^
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   s   &r   r   Ú/DeviceAuthorizationClass._use_device_code_grant+   s<   € ð 	×!Ñ!Ô#ÜðØ×7Ñ7Ð8ð:ô	
ð 	×%Ñ%Ö'r   c                óB  € R\          2pRR/p\        '       g   \        R4      h \        P                  ! V P
                  VV\        R7      pVP                  4        VP                  4       pVP                  R4      V n
        VP                  R4      V n        VP                  R4      V n        VP                  R	4      V n        VP                  R
4      V n        R#   \        P                   d,   p\        P                  ! RXP                    RT 24      hRp?ii ; i)zU
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ÚtimeoutÚ	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   r   Úraise_for_statusÚjsonÚgetÚ
_user_codeÚ_verification_uriÚ	_intervalr   r   Ú	HTTPErrorÚstatus_code)r   r    r!   ÚresÚresponseÚes   &     r   r   Ú-DeviceAuthorizationClass._request_device_code9   s  € ð Ô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   ¦B6C ÃDÃ3&DÄDc                óÞ  € R\         R\        RV P                  /p\        '       g   \	        R4      hV P
                  fè   \        P                  ! V P                  4        \        P                  ! V P                  V\        R7      pVP                  pV^È8X  d5   \        P                  R4       V P!                  VP#                  4       4       VR9  d   \	        W2P$                  4      hVR8X  d4   VP#                  4       R	,          R9  d   \	        W2P$                  4      hKó  Kõ  R#   \        P&                  P(                   d%   p\        P+                  R
T 24        Rp?EK5  Rp?ii ; i)zi
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é�  Úerrorz)Error was found while posting a request: )éÈ   r>   )Úauthorization_pendingÚ	slow_down)ÚGRANT_TYPE_DEVICE_CODEr)   r   r*   r+   r   ÚtimeÚsleepr3   r,   r-   r   r   r5   ÚloggerÚinfoÚ_set_token_datar/   ÚtextÚ
exceptionsÚRequestExceptionr?   )r   Ú
token_dataÚcheck_auth_completionr5   r8   s   &    r   r   Ú1DeviceAuthorizationClass.poll_for_auth_completionX   sI  € ð #Ô$:Ø!Ô#8Ø# T×%7Ñ%7ð9ˆ
÷ ‹Üð @ó Að Aà× Ñ Ò(Ü�JŠJ�t—~‘~Ô&ðNÜ(0¯ª°d×6IÑ6IØ;EÜ>Mô)OÐ%ð 4×?Ñ?�à #Ô%Ü—K‘KÐ FÔGØ×(Ñ(Ð)>×)CÑ)CÓ)EÔFØ jÔ0Ü# K×1KÑ1KÓLÐLØ #Ô%Ø)×.Ñ.Ó0°Õ9Ø>ô?ä# K×1KÑ1KÓLÐLñ?ñ &ñ )øô$ ×&Ñ&×7Ñ7ô NÜ—‘ÐHÈÈÐL×MÓMûðNús   Á!CD) Ä)E,ÅE'Å'E,c                óô  € VP                  R4      V n        \        P                  ! \        P
                  4      \        VP                  R4      R7      ,           V n        VP                  R4      V n        VP                  R4      V n	        V P                  ^ 8X  d   \        P                  V n        R# \        P                  ! \        P
                  4      \        V P                  R7      ,           V n        R# )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_inN)r0   r   r   Únowr   Úutcr   r   Ú_refresh_tokenÚ_refresh_expires_inÚmaxÚ_refresh_expires_at)r   rL   s   &&r   rH   Ú(DeviceAuthorizationClass._set_token_dataz   s¥   € ð (Ÿ^™^¨NÓ;ˆÔÜ"*§,¢,¬x¯|©|Ó"<Ü˜jŸn™n¨\Ó:Ô;õ#<ˆÔà(Ÿn™n¨_Ó=ˆÔØ#-§>¡>Ð2FÓ#GˆÔ Ø×#Ñ# qÔ(Ü'/§|¡|ˆDÖ$ä'/§|¢|´H·L±LÓ'AÜ $×":Ñ":Ô;õ(<ˆDÖ$r   c                óâ   € V P                  4       '       d   V P                  # V P                  4       '       d   V P                  4        V P                  # V P	                  4        V P                  # )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   s   &r   Úget_access_tokenÚ)DeviceAuthorizationClass.get_access_token�   s^   € ð ×%Ñ%×'Ò'Ø×%Ñ%Ð%Ø×&Ñ&×(Ò(Ø×)Ñ)Ô+Ø×%Ñ%Ð%Ø×#Ñ#Ô%Ø×!Ñ!Ð!r   c                óÖ   € V P                   ;'       dW    V P                  ;'       dC    V P                  \        ^´R7      ,
          \        P                  ! \
        P                  4      8„  # )z‚
Check the validity of access_token. We are considering it invalid 180
sec. prior to it's exact expiry time.
:return: True/False

rR   )r   r   r   r   rV   r   rW   r   s   &r   r^   Ú.DeviceAuthorizationClass.is_access_token_valid›   sV   € ð ×!Ñ!÷ 'ð ' d×&=Ñ&=÷ 'ð 'Ø×#Ñ#¤i¸Ô&<Õ<Ü�LŠLœŸ™Ó&ñ'ð	'r   c                óÖ   € V P                   ;'       dW    V P                  ;'       dC    V P                  \        ^´R7      ,
          \        P                  ! \
        P                  4      8„  # )z„
Check the validity of refresh_token. We are considering it invalid
180 sec. prior to it's exact expiry time.

:return: True/False

rR   )rX   r[   r   r   rV   r   rW   r   s   &r   r_   Ú/DeviceAuthorizationClass.is_refresh_token_valid¦   sV   € ð ×"Ñ"÷ 'ð ' t×'?Ñ'?÷ 'ð 'Ø×$Ñ$¤y¸Ô'=Õ=Ü�LŠLœŸ™Ó&ñ'ð	'r   Nc                óv  € \         '       g   \        R4      hR\        RRRV'       g   V P                  MT/p\        P
                  ! V P                  V\        R7      pVP                  ^È8X  d"   V P                  VP                  4       4       R# VP                  R8X  dj   RVP                  4       R,          9   dN   \        P                  R	VP                   R
VP                  4       R,           R24       V P                  4        R# \        RVP                   RVP                  4       R,           24      h)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

r   r<   r;   rT   r=   r>   Ú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)   rX   r,   r-   r   r   r5   rH   r/   rF   Úwarningr   )r   rT   Úrefresh_token_dataÚrefresh_token_ress   &&  r   r`   Ú1DeviceAuthorizationClass._use_refresh_token_grant²   s@  € ÷ ‹Üð @ó Að Aà)Ô+@Ø*¨OØ-ß+ð 04×/BÒ/BØ1>ð@Ðô
 %ŸMšM¨$×*=Ñ*=Ø/AÜ2AôCÐð ×(Ñ(¨CÔ/Ø× Ñ Ð!2×!7Ñ!7Ó!9Ö:à×*Ñ*¨cÔ1°iØ!×&Ñ&Ó(¨Õ1ô72ä�N‰Nð -Ø->×-JÑ-JÐ,KÈ1Ø/×4Ñ4Ó6°wÕ?Ð@ð ABðBô Cð ×'Ñ'Ö)äð)à):×)FÑ)FÐ(GØÐ/×4Ñ4Ó6°wÕ?Ð@ðBóCð Cr   )Ú__device_coder   r   r3   r[   rY   rX   r1   r2   r   r   r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   r   r   rH   ra   r^   r_   r`   Ú__static_attributes__Ú__classdictcell__)Ú__classdict__s   @r   r	   r	      s@   ø‡ € ñò&ò(ò-ò> NòD<ò&"ò	'ò
'÷"Cò "Cr   r	   )Úloggingr,   r*   ÚImportErrorrD   r   r   r   Úsos.utilitiesr   r)   rC   Ú	getLoggerrF   r	   © r   r   Ú<module>r{      se   ðó ðÛØ€Oó ß 2Ñ 2å )à#Ð ØGÐ à	×	Ò	˜5Ó	!€÷xCó xCøð ô Ø‚Oðús   †A Á	AÁA