@@ -12,7 +12,7 @@ class AuthenticationContext(BaseAuthenticationContext):
12
12
13
13
def __init__ (self , url , credentials = None ):
14
14
"""
15
- Authentication context for SharePoint Online/One Drive
15
+ Authentication context for SharePoint Online/OneDrive
16
16
17
17
:param str url: authority url
18
18
:param ClientCredential or UserCredential credentials: credentials
@@ -33,9 +33,9 @@ def set_token(self, token):
33
33
34
34
def acquire_token (self ):
35
35
if isinstance (self .credentials , ClientCredential ):
36
- self .acquire_token_for_app (self .credentials .clientId , self .credentials .clientSecret )
36
+ return self .acquire_token_for_app (self .credentials .clientId , self .credentials .clientSecret )
37
37
elif isinstance (self .credentials , UserCredential ):
38
- self .acquire_token_for_user (self .credentials .userName , self .credentials .password )
38
+ return self .acquire_token_for_user (self .credentials .userName , self .credentials .password )
39
39
else :
40
40
raise ValueError ("Unknown credential type" )
41
41
@@ -48,19 +48,30 @@ def acquire_token_for_user(self, username, password):
48
48
self .provider = SamlTokenProvider (self .url , username , password )
49
49
if not self .provider .acquire_token ():
50
50
raise ValueError ('Acquire token failed: {0}' .format (self .provider .error ))
51
+ return True
51
52
52
53
def acquire_token_for_app (self , client_id , client_secret ):
53
54
"""Acquire token via client credentials (SharePoint App Principal)"""
54
55
self .provider = ACSTokenProvider (self .url , client_id , client_secret )
55
56
if not self .provider .acquire_token ():
56
57
raise ValueError ('Acquire token failed: {0}' .format (self .provider .error ))
58
+ return True
57
59
58
- def acquire_token_password_grant (self , client_credentials , user_credentials ):
59
- """Acquire token via resource owner password credential (ROPC) grant"""
60
+ def acquire_token_password_grant (self , client_id , username , password , resource , scope ):
61
+ """
62
+ Acquire token via resource owner password credential (ROPC) grant
63
+
64
+ :param str resource: A URI that identifies the resource for which the token is valid.
65
+ :param str username: : The username of the user on behalf this application is authenticating.
66
+ :param str password: The password of the user named in the username parameter.
67
+ :param str client_id: str The OAuth client id of the calling application.
68
+ :param list[str] scope:
69
+ """
60
70
self .provider = OAuthTokenProvider (self .url )
61
- return self .provider .acquire_token_password_type ("https://outlook.office365.com" ,
62
- client_credentials ,
63
- user_credentials )
71
+ return self .provider .acquire_token_password_type (resource = resource ,
72
+ client_id = client_id ,
73
+ user_credentials = UserCredential (username , password ),
74
+ scope = scope )
64
75
65
76
def authenticate_request (self , request_options ):
66
77
"""Authenticate request
0 commit comments