
    3fiSB                     `    d dl Z d dlmZmZmZmZmZ ddlmZm	Z	m
Z
 ddlmZmZ  G d d      Zy)    N)CallableListOptionalTupleType   )
ConnectionMSGraphProtocolProtocol)ME_RESOURCEconsent_input_tokenc                      e Zd ZU eZeed<   dddddeeef   de	e   de	e
   de	e   fdZd	 Zed
efd       Zddedde	e   de	e   ded
efdZ	 d0dee   de	e   d
eeef   fdZddddde	e   dede	ee      ded
ef
dZed
e	e   fd       Zd
ee   fdZej4                  de	e   d
dfd       Zd Zed        Zd0de	e   fdZd0de	e   fdZdd d!de	e   d"efd#Zd0de	e   fd$Z dd%de	e   fd&Z!dd%de	e   fd'Z"d(d%defd)Z#d(d%defd*Z$d(d%defd+Z%d(d%defd,Z&d(d%defd-Z'd(d%defd.Z(d(d%defd/Z)y)1Accountconnection_constructorN)usernameprotocolmain_resourcecredentialsr   r   r   c                   |xs t         }t        |t              r
 |dd|i|}|| _        t        | j                  t              st        d      |j                  dd      }|dvrt        d      |j                  dd      }|r|d= t        j                  d	t               |d
k(  r:| j                  j                  t        k(  rd| j                  _
        |t        k(  rAd}n>|dk(  r9| j                  j                  t        k(  rd| j                  _
        |t        k(  rd}||d<    | j                  |fi || _        |xs | j                  j                  | _        y)a   Creates an object which is used to access resources related to the specified credentials.

        :param credentials: a tuple containing the client_id and client_secret
        :param username: the username to be used by this account
        :param protocol: the protocol to be used in this account
        :param main_resource: the resource to be used by this account ('me' or 'users', etc.)
        :param kwargs: any extra args to be passed to the Connection instance
        :raises ValueError: if an invalid protocol is passed
        default_resourcez)'protocol' must be a subclass of Protocolauth_flow_typeauthorization)r   publicr   passwordzO"auth_flow_type" must be "authorization", "credentials", "password" or "public"scopesNz7Since 2.1 scopes are only needed during authentication.r    r   r    )r
   
isinstancetyper   r   
ValueErrorgetwarningswarnDeprecationWarningr   r   r   conr   )selfr   r   r   r   kwargsr   r   s           J/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/O365/account.py__init__zAccount.__init__   s<    .h%II&IH"*$--2HII$4oF!WWnooHd+x MMSUgh]*}}--<13.+ "z)}}--<13.+ "%z.4..{EfE"/"Q4==3Q3Q    c                 h    | j                   j                  rd| j                   j                  d    S y)NzAccount Client Id: r   zUnidentified Account)r%   authr&   s    r(   __repr__zAccount.__repr__@   s+    88==(q)9(:;;)r*   returnc                 n   | j                   j                  j                  du r| j                   j                         du ry| j                   j                  j	                  | j                   j
                        xs; | j                   j                  j                  | j                   j
                         S )a  
        Checks whether the library has the authentication data and that is not expired for the current username.
        This will try to load the token from the backend if not already loaded.
        Return True if authenticated, False otherwise.
        Fr   )r%   token_backendhas_dataload_token_from_backendtoken_is_long_livedr   token_is_expiredr-   s    r(   is_authenticatedzAccount.is_authenticatedF   s     88!!**e3xx//1U: &&::DHHDUDU:V [xx-->>HYHY>ZZ	
r*   )requested_scopesredirect_urihandle_consentr8   r9   r:   c                ^   | j                   j                  dv r_ | j                  |fd|i|\  }} ||      }|r1 | j                  |fd|i|}|rt	        d       |S t	        d       |S t	        d       y| j                   j                  dv r | j                  dd	|i|S t        d
      )a   Performs the console authentication flow resulting in a stored token.
        It uses the credentials passed on instantiation.
        Returns True if succeeded otherwise False.

        :param list[str] requested_scopes: list of protocol user scopes to be converted
         by the protocol or scope helpers or raw scopes
        :param str redirect_uri: redirect url configured in registered app
        :param handle_consent: a function to handle the consent process by default just input for the token url
        :param kwargs: other configurations to be passed to the
         Connection.get_authorization_url and Connection.request_token methods
        r   r   r9   flowzRAuthentication Flow Completed. Oauth Access Token Stored. You can now use the API.z%Something go wrong. Please try again.zAuthentication Flow aborted.F)r   r   r8   zO"auth_flow_type" must be "authorization", "public", "password" or "credentials"N)r%   r   get_authorization_urlrequest_tokenprintr    )	r&   r8   r9   r:   r'   consent_urlr=   	token_urlresults	            r(   authenticatezAccount.authenticateW   s     88""&AA : : :;K qZf qjp qK&{3I+++IKDKFKno  AB45XX$$(CC%4%%X=MXQWXX noor*   c                 v    | j                   j                  |      } | j                  j                  |fd|i|S )a   Initializes the oauth authorization flow, getting the
        authorization url that the user must approve.

        :param list[str] requested_scopes: list of scopes to request access for
        :param str redirect_uri: redirect url configured in registered app
        :param kwargs: allow to pass unused params in conjunction with Connection
        :return: authorization url and the flow dict
        r9   )r   get_scopes_forr%   r?   )r&   r8   r9   r'   s       r(   r?   zAccount.get_authorization_url|   s=      ==778HI-txx--.>d\d]cddr*   Tr=   r8   store_tokenauthorization_urlr=   rI   c                   | j                   j                  dk(  rY|s| j                  j                  d      g}nt	        |      dkD  s!|d   | j                  j                  d      k7  rt        d      | j                   j                  dk(  r;|r| j                  j                  |      }nB| j                  j                  d      g}n%|r#t        d| j                   j                   d       | j                   j                  |f|||d	|S )
a   Authenticates for the specified url and gets the oauth token data. Saves the
        token in the backend if store_token is True. This will replace any other tokens stored
        for the same username and scopes requested.
        If the token data is successfully requested, then this method will try to set the username if
        not previously set.

        :param str or None authorization_url: url given by the authorization flow or None if it's client credentials
        :param dict flow: dict object holding the data used in get_authorization_url
        :param list[str] requested_scopes: list of scopes to request access for
        :param bool store_token: True to store the token in the token backend,
         so you don't have to keep opening the auth link and
         authenticating every time
        :param kwargs: allow to pass unused params in conjunction with Connection
        :return: Success/Failure
        :rtype: bool
        r   z.defaultr   r   zeProvided scope for auth flow type "credentials" does not match default scope for the current protocolr   zAuth flow type "z" does not require scopesrH   )r%   r   r   prefix_scopelenr    rG   r@   )r&   rJ   r=   r8   rI   r'   s         r(   r@   zAccount.request_token   s   * 88""m3#$(MM$>$>z$J#K '(1,0@0Ct}}GaGablGm0m$ &N O OXX$$
2#'==#?#?@P#Q $(MM$>$>z$J#K  #3DHH4K4K3LLe!fgg%txx%%&7 I+/7G2=I BHI 	Ir*   c                 .    | j                   j                  S )z, Returns the username in use for the accountr%   r   r-   s    r(   r   zAccount.username   s     xx   r*   c                    g }| j                   j                  }| j                   j                  j                         D ]L  }|j                  d      }|s|j	                  |      s|j                  |      r<|j                  |       N |S )ze Returns a list of usernames that are authenticated and have a valid access token or a refresh token.r   r1   )r%   r2   get_all_accountsr!   r5   r6   append)r&   	usernamestbaccountr   s        r(   get_authenticated_usernamesz#Account.get_authenticated_usernames   s    	XX##xx-->>@ 	+G{{:.HR33X3FbNaNaksNaNt  *	+
 r*   c                 &    || j                   _        y)z
        Sets the username in use for this account
        The username can be None, meaning the first user account retrieved from the token_backend
        NrO   )r&   r   s     r(   r   zAccount.username   s     %r*   c                     | j                   j                  dv r&| j                  t              }|j	                         S y)z9 Returns the current user data from the active directory r<   resourceN)r%   r   	directoryr   get_current_user)r&   r[   s     r(   get_current_user_datazAccount.get_current_user_data   s7    88""&AA<I--//r*   c                     | j                   S )zO Alias for self.con

        :rtype: type(self.connection_constructor)
        )r%   r-   s    r(   
connectionzAccount.connection   s     xxr*   rZ   c                 $    ddl m}  || |d      S )z Creates a new message to be sent or stored

        :param str resource: Custom resource to be used in this message
         (Defaults to parent main_resource)
        :return: New empty message
        :rtype: Message
        r   )MessageT)parentr   is_draft)messagera   )r&   rZ   ra   s      r(   new_messagezAccount.new_message   s     	%d(TJJr*   c                 $    ddl m}  || |d      S )a   Get an instance to the mailbox for the specified account resource

        :param resource: Custom resource to be used in this mailbox
         (Defaults to parent main_resource)
        :return: a representation of account mailbox
        :rtype: O365.mailbox.MailBox
        r   )MailBoxrg   rb   r   name)mailboxrg   )r&   rZ   rg   s      r(   rj   zAccount.mailbox   s     	%d(KKr*   personal)rZ   address_bookrl   c                    |j                         dk(  rddlm}  || |d      S |j                         dv rddlm}  || |      S t        d	      )
a   Get an instance to the specified address book for the
        specified account resource

        :param resource: Custom resource to be used in this address book
         (Defaults to parent main_resource)
        :param address_book: Choose from 'Personal' or 'Directory'
        :return: a representation of the specified address book
        :rtype: AddressBook or GlobalAddressList
        :raises RuntimeError: if invalid address_book is specified
        rk   r   )AddressBookzPersonal Address Bookrh   )galr[   )	Directoryrb   r   z`address_book must be either "Personal" (resource address book) or "Directory" (Active Directory))lowerrl   rn   r[   rp   RuntimeError)r&   rZ   rl   rn   rp   s        r(   rl   zAccount.address_book   sc     :-1d($;= =!%99,DAALM Mr*   c                 .    ddl m}m}  || |xs |      S )z& Returns the active directory instancer   )USERS_RESOURCErp   rq   )r[   ru   rp   )r&   rZ   ru   rp   s       r(   r[   zAccount.directory  s    8H4NOOr*   rY   c                "    ddl m}  || |      S )a(   Get an instance to work with calendar events for the
        specified account resource

        :param resource: Custom resource to be used in this schedule object
         (Defaults to parent main_resource)
        :return: a representation of calendar events
        :rtype: Schedule
        r   )Schedulerq   )calendarrw   )r&   rZ   rw   s      r(   schedulezAccount.schedule  s     	't8<<r*   c                l    t        | j                  t              st        d      ddlm}  || |      S )a   Get an instance to handle file storage (OneDrive / Sharepoint)
        for the specified account resource

        :param resource: Custom resource to be used in this drive object
         (Defaults to parent main_resource)
        :return: a representation of OneDrive File Storage
        :rtype: Storage
        :raises RuntimeError: if protocol doesn't support the feature
        z/Drive options only works on Microsoft Graph APIr   )Storagerq   )r   r   r
   rs   driver{   )r&   rZ   r{   s      r(   storagezAccount.storage"  s4     $--9AC C"d(;;r*   r   c                l    t        | j                  t              st        d      ddlm}  || |      S )a   Get an instance to read information from Sharepoint sites for the
        specified account resource

        :param resource: Custom resource to be used in this sharepoint
         object (Defaults to parent main_resource)
        :return: a representation of Sharepoint Sites
        :rtype: Sharepoint
        :raises RuntimeError: if protocol doesn't support the feature
        z0Sharepoint api only works on Microsoft Graph APIr   )
Sharepointrq   )r   r   r
   rs   
sharepointr   )r&   rZ   r   s      r(   r   zAccount.sharepoint3  s6     $--9BD D 	+X>>r*   c                l    t        | j                  t              st        d      ddlm}  || |      S )z< Get an instance to read information from Microsoft planner z-planner api only works on Microsoft Graph APIr   )Plannerrq   )r   r   r
   rs   plannerr   )r&   rZ   r   s      r(   r   zAccount.plannerF  s6     $--9?A A 	%d(;;r*   c                "    ddl m}  || |      S )z9 Get an instance to read information from Microsoft ToDo r   )ToDorq   )tasksr   )r&   rZ   r   s      r(   r   zAccount.tasksQ  s     	 4x88r*   c                l    t        | j                  t              st        d      ddlm}  || |      S )z: Get an instance to read information from Microsoft Teams z+teams api only works on Microsoft Graph APIr   )Teamsrq   )r   r   r
   rs   teamsr   )r&   rZ   r   s      r(   r   zAccount.teamsX  s4     $--9=? ? 	!D99r*   c                "    ddl m}  || |      S )zH Returns a Categories object to handle the available Outlook Categories r   )
Categoriesrq   )categoryr   )r&   rZ   r   s      r(   outlook_categorieszAccount.outlook_categoriesb  s    (X>>r*   c                l    t        | j                  t              st        d      ddlm}  || |      S )z; Get an instance to read information from Microsoft Groups z,groups api only works on Microsoft Graph APIr   )Groupsrq   )r   r   r
   rs   groupsr   )r&   rZ   r   s      r(   r   zAccount.groupsh  s6     $--9>@ @ 	#T::r*   c                "    ddl m}  || |      S )z2 Get an instance to manage MS Graph subscriptions r   )Subscriptionsrq   )subscriptionsr   )r&   rZ   r   s      r(   r   zAccount.subscriptionsr  s     	1DAAr*   r>   )*__name__
__module____qualname__r	   r   r   __annotations__r   strr   r   r)   r.   propertyboolr7   r   listr   rE   r   dictr?   r@   r   rV   setterr]   r_   re   rj   rl   r[   ry   r}   r   r   r   r   r   r   r   r   r*   r(   r   r      s   #-D- ,004043RE#s(O 3R#C=3R#H-3R !)3Rj* 
$ 
 
  BFei0C#p #pU]^aUb #p%-#pRV#pN =Ae04S	e,4SMe ,1d+;e& $(>B*.(Ix} (I (I(0c(;(I $((I $(	(IT !(3- ! !	T#Y 	 __%# %4 % %  	KHSM 	K	L 	L 9=R\ M MC M4P(3- P 59 
=HSM 
= 48 <8C= <" -/ ?c ?& *, 	<3 	< (* 9 9 (* : : 57 ?c ? )+ ;# ; 02 B Br*   r   )r"   typingr   r   r   r   r   r_   r	   r
   r   utilsr   r   r   r   r*   r(   <module>r      s%     8 8 = = 3nB nBr*   