
    qh                     V    S r SSKJrJrJr  SSKrSSKJrJr  SSKJ	r	   " S S	\	5      r
g)
zw
ExactTarget OAuth support.
Support Authentication from IMH using JWT token and pre-shared key.
Requires package pyjwt
    )datetime	timedeltatimezoneN   )AuthCanceled
AuthFailed   )
BaseOAuth2c                   L    \ rS rSrSrS rS rS rS rS r	S r
S	 rSS jrSrg
)ExactTargetOAuth2   exacttargetc                     UR                  S0 5      R                  S0 5      R                  S0 5      nSU;   a  US   US'   U$ )z2Use the email address of the user, suffixed by _ettokenrequestuseremailusername)get)selfresponser   s      R/var/www/html/env/lib/python3.13/site-packages/social_core/backends/exacttarget.pyget_user_details"ExactTargetOAuth2.get_user_details   sF    ||GR(,,Y;??Kd?#G}D    c                 B    SR                  UR                  S5      5      $ )a  
Create a user ID from the ET user ID. Uses details rather than the
default response, as only the token is available in response. details
is much richer:
    {
        'expiresIn': 1200,
        'username': 'example@example.com',
        'refreshToken': '1234567890abcdef',
        'internalOauthToken': 'jwttoken.......',
        'oauthToken': 'yetanothertoken',
        'id': 123456,
        'culture': 'en-US',
        'timezone': {
            'shortName': 'CST',
            'offset': -6.0,
            'dst': False,
            'longName': '(GMT-06:00) Central Time (No Daylight Saving)'
        },
        'email': 'example@example.com'
    }
z{}id)formatr   )r   detailsr   s      r   get_user_idExactTargetOAuth2.get_user_id   s    , {{7;;t,--r   c                     g)NF r   s    r   uses_redirectExactTargetOAuth2.uses_redirect1   s    r   c                     g Nr#   r$   s    r   auth_urlExactTargetOAuth2.auth_url4   s    r   c                     UR                  S5      (       a<  U R                  R                  S5      =(       d    U R                  S   n[        X5      eg )Nerrorerror_description)r   datar   )r   r.   r,   s      r   process_errorExactTargetOAuth2.process_error7   sB    88GIIMM"56L$))G:LET)) r   c                     U R                  5       u  pE [        R                  " XS/S9nUR                  SU0U S.5        U R                  R                  " U0 UD6$ ! [        R                   a    [	        U 5      ef = f)NHS256)
algorithmsr   )r   backend)get_key_and_secretjwtdecodeDecodeErrorr   updatestrategyauthenticate)r   r   argskwargsdummysecretdecodeds          r   do_authExactTargetOAuth2.do_auth<   s{    //1	%jjG9EG 	GW#5$GH}}))4:6::  	%t$$	%s   A  A<c                     U R                   R                  S0 5      nU(       d  [        U S5      eU R                  " U/UQ70 UD6$ )z2Completes login process, must return user instancer6   zAuthentication Failed)r.   r   r   rA   )r   r<   r=   r   s       r   auth_completeExactTargetOAuth2.auth_completeE   s@    		eR(T#:;;||E3D3F33r   Nc                 J   UR                  S5      UR                  S5      UR                  S5      UR                  S5      UR                  S5      S.nUR                  SS5      S	-
  n[        R                  " [        R                  5      [        US
9-   n	U	[        SSS5      -
  R                  5       US'   UR                  S5      (       aU  US   n
U
R                  S0 5      R                  S5      nU(       a(  UR                  S5      US'   UR                  S5      US'   U$ )z%Load extra details from the JWT tokenr   r   internalOauthToken
oauthTokenrefreshToken)r   r   rG   rH   rI   	expiresInr      )secondsi  r	   expiresr   r   organizationstackKeystackenterpriseId)r   r   nowr   utcr   total_seconds)r   r   uidr   r   r<   r=   r.   expiresSecondsrM   r   orgs               r   
extra_dataExactTargetOAuth2.extra_dataL   s     ++d#[[) #*++.B"C!++l3 $KK7
 ![!4r9,,x||,y/PP"XdAq%99HHJY<<  W%E))Ir*..~>C #
 3W'*ww~'>^$r   r#   r(   )__name__
__module____qualname____firstlineno__namer   r    r%   r)   r/   rA   rD   rX   __static_attributes__r#   r   r   r   r      s/    D.0*
;4r   r   )__doc__r   r   r   r6   
exceptionsr   r   oauthr
   r   r#   r   r   <module>rc      s)    3 2 
 1 X
 Xr   