4
4
5
5
6
6
class ClientApplication (object ):
7
- DEFAULT_AUTHORITY = "https://login.microsoftonline.com/common/"
8
7
9
8
def __init__ (
10
9
self , client_id ,
11
- validate_authority = True , authority = DEFAULT_AUTHORITY ):
10
+ authority_url = "https://login.microsoftonline.com/common/" ,
11
+ validate_authority = True ):
12
12
self .client_id = client_id
13
- self .validate_authority = validate_authority
14
- self .authority = authority
13
+ self .authority = Authority (authority_url , validate_authority )
15
14
16
15
def acquire_token_silent (
17
16
self , scope ,
@@ -20,12 +19,13 @@ def acquire_token_silent(
20
19
policy = '' ,
21
20
force_refresh = False , # To force refresh an Access Token (not a RT)
22
21
** kwargs ):
23
- a = Authority (self . authority , policy = policy ) # TODO
22
+ a = Authority (authority ) if authority else self . authority
24
23
client = oauth2 .Client (self .client_id , token_endpoint = a .token_endpoint )
25
24
refresh_token = kwargs .get ('refresh_token' ) # For testing purpose
26
25
response = client .get_token_by_refresh_token (
27
26
refresh_token , scope = scope ,
28
- client_secret = getattr (self , 'client_credential' )) # TODO: JWT too
27
+ client_secret = getattr (self , 'client_credential' ), # TODO: JWT too
28
+ query = {'policy' : policy } if policy else None )
29
29
# TODO: refresh the refresh_token
30
30
return response
31
31
@@ -106,13 +106,13 @@ def get_authorization_request_url(
106
106
sending them on the wire.)
107
107
:param str state: Recommended by OAuth2 for CSRF protection.
108
108
"""
109
- a = Authority (self . authority , policy = policy ) # TODO
109
+ a = Authority (authority ) if authority else self . authority
110
110
grant = oauth2 .AuthorizationCodeGrant (
111
111
self .client_id , authorization_endpoint = a .authorization_endpoint )
112
112
return grant .authorization_url (
113
- redirect_uri = redirect_uri ,
113
+ redirect_uri = redirect_uri , state = state , login_hint = login_hint ,
114
114
scope = scope , # TODO: handle additional_scope
115
- state = state , login_hint = login_hint ,
115
+ policy = policy if policy else None ,
116
116
** (extra_query_params or {}))
117
117
118
118
def acquire_token_by_authorization_code (
@@ -148,12 +148,12 @@ def acquire_token_by_authorization_code(
148
148
# So only omit this when you are working with only one scope.
149
149
scope = scope or ["openid" , "email" , "profile" , "offline_access" ] # TBD
150
150
151
- a = Authority (self .authority , policy = policy ) # TODO
152
151
grant = oauth2 .AuthorizationCodeGrant (
153
- self .client_id , token_endpoint = a .token_endpoint )
152
+ self .client_id , token_endpoint = self . authority .token_endpoint )
154
153
return grant .get_token (
155
154
code , scope = scope , redirect_uri = redirect_uri ,
156
- client_secret = self .client_credential )
155
+ client_secret = self .client_credential , # TODO: Support certificate
156
+ query = {'policy' : policy } if policy else None )
157
157
158
158
def acquire_token_on_behalf_of (
159
159
self , user_assertion , scope , authority = None , policy = '' ):
0 commit comments