MCPcopy Create free account
hub / github.com/O365/python-o365 / Account

Class Account

O365/account.py:8–364  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6
7
8class Account:
9 connection_constructor: Type = Connection
10
11 def __init__(self, credentials: Tuple[str, str], *,
12 username: Optional[str] = None,
13 protocol: Optional[Protocol] = None,
14 main_resource: Optional[str] = None, **kwargs):
15 """ Creates an object which is used to access resources related to the specified credentials.
16
17 :param credentials: a tuple containing the client_id and client_secret
18 :param username: the username to be used by this account
19 :param protocol: the protocol to be used in this account
20 :param main_resource: the resource to be used by this account ('me' or 'users', etc.)
21 :param kwargs: any extra args to be passed to the Connection instance
22 :raises ValueError: if an invalid protocol is passed
23 """
24
25 protocol = protocol or MSGraphProtocol # Defaults to Graph protocol
26 if isinstance(protocol, type):
27 protocol = protocol(default_resource=main_resource, **kwargs)
28 self.protocol: Protocol = protocol
29
30 if not isinstance(self.protocol, Protocol):
31 raise ValueError("'protocol' must be a subclass of Protocol")
32
33 auth_flow_type = kwargs.get('auth_flow_type', 'authorization')
34
35 if auth_flow_type not in ['authorization', 'public', 'credentials', 'password']:
36 raise ValueError('"auth_flow_type" must be "authorization", "credentials", "password" or "public"')
37
38 scopes = kwargs.get('scopes', None)
39 if scopes:
40 warnings.warn("Since 3.0 scopes are only needed during authentication.", DeprecationWarning)
41
42 if auth_flow_type == 'credentials':
43 # set main_resource to blank when it's the 'ME' resource
44 if self.protocol.default_resource == ME_RESOURCE:
45 self.protocol.default_resource = ''
46 if main_resource == ME_RESOURCE:
47 main_resource = ''
48
49 elif auth_flow_type == 'password':
50 # set main_resource to blank when it's the 'ME' resource
51 if self.protocol.default_resource == ME_RESOURCE:
52 self.protocol.default_resource = ''
53 if main_resource == ME_RESOURCE:
54 main_resource = ''
55
56 kwargs['username'] = username
57
58 self.con = self.connection_constructor(credentials, **kwargs)
59 self.main_resource: str = main_resource or self.protocol.default_resource
60
61 def __repr__(self):
62 if self.con.auth:
63 return f'Account Client Id: {self.con.auth[0]}'
64 else:
65 return 'Unidentified Account'

Callers 7

test_authenticationMethod · 0.90
setup_classMethod · 0.90
setup_classMethod · 0.90
teamsFunction · 0.90
__init__Method · 0.90

Calls

no outgoing calls

Tested by 5

test_authenticationMethod · 0.72
setup_classMethod · 0.72
setup_classMethod · 0.72
teamsFunction · 0.72