Skip to content

Commit 7ead4a3

Browse files
committed
Most acquisitions support policy now
1 parent 5df3dce commit 7ead4a3

File tree

3 files changed

+14
-23
lines changed

3 files changed

+14
-23
lines changed

msal/application.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44

55

66
class ClientApplication(object):
7-
DEFAULT_AUTHORITY = "https://login.microsoftonline.com/common/"
87

98
def __init__(
109
self, client_id,
11-
validate_authority=True, authority=DEFAULT_AUTHORITY):
10+
authority_url="https://login.microsoftonline.com/common/",
11+
validate_authority=True):
1212
self.client_id = client_id
13-
self.validate_authority = validate_authority
14-
self.authority = authority
13+
self.authority = Authority(authority_url, validate_authority)
1514

1615
def acquire_token_silent(
1716
self, scope,
@@ -20,12 +19,13 @@ def acquire_token_silent(
2019
policy='',
2120
force_refresh=False, # To force refresh an Access Token (not a RT)
2221
**kwargs):
23-
a = Authority(self.authority, policy=policy) # TODO
22+
a = Authority(authority) if authority else self.authority
2423
client = oauth2.Client(self.client_id, token_endpoint=a.token_endpoint)
2524
refresh_token = kwargs.get('refresh_token') # For testing purpose
2625
response = client.get_token_by_refresh_token(
2726
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)
2929
# TODO: refresh the refresh_token
3030
return response
3131

@@ -106,13 +106,13 @@ def get_authorization_request_url(
106106
sending them on the wire.)
107107
:param str state: Recommended by OAuth2 for CSRF protection.
108108
"""
109-
a = Authority(self.authority, policy=policy) # TODO
109+
a = Authority(authority) if authority else self.authority
110110
grant = oauth2.AuthorizationCodeGrant(
111111
self.client_id, authorization_endpoint=a.authorization_endpoint)
112112
return grant.authorization_url(
113-
redirect_uri=redirect_uri,
113+
redirect_uri=redirect_uri, state=state, login_hint=login_hint,
114114
scope=scope, # TODO: handle additional_scope
115-
state=state, login_hint=login_hint,
115+
policy=policy if policy else None,
116116
**(extra_query_params or {}))
117117

118118
def acquire_token_by_authorization_code(
@@ -148,12 +148,12 @@ def acquire_token_by_authorization_code(
148148
# So only omit this when you are working with only one scope.
149149
scope = scope or ["openid", "email", "profile", "offline_access"] # TBD
150150

151-
a = Authority(self.authority, policy=policy) # TODO
152151
grant = oauth2.AuthorizationCodeGrant(
153-
self.client_id, token_endpoint=a.token_endpoint)
152+
self.client_id, token_endpoint=self.authority.token_endpoint)
154153
return grant.get_token(
155154
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)
157157

158158
def acquire_token_on_behalf_of(
159159
self, user_assertion, scope, authority=None, policy=''):

msal/client_credential.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class ClientCredentialRequest(BaseRequest):
1313
def __init__(self, **kwargs):
1414
super(ClientCredentialRequest, self).__init__(**kwargs)
1515
self.grant = ClientCredentialGrant(
16-
self.client_id, token_endpoint=self.token_endpoint)
16+
self.client_id, token_endpoint=self.authority.token_endpoint)
1717

1818
def get_token(self):
1919
if isinstance(self.client_credential, dict):

msal/request.py

+1-10
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,6 @@ def __init__(
1717
raise ValueError("scope cannot be empty")
1818
self.__dict__.update(locals())
1919

20-
# TODO: Temporary solution here
21-
self.token_endpoint = authority
22-
if authority.startswith('https://login.microsoftonline.com/common/'):
23-
self.token_endpoint += 'oauth2/v2.0/token'
24-
elif authority.startswith('https://login.windows.net/'): # AAD?
25-
self.token_endpoint += 'oauth2/token'
26-
if policy:
27-
self.token_endpoint += '?policy={}'.format(policy)
28-
2920
def run(self):
3021
"""Returns a dictionary, which typically contains following keys:
3122
@@ -38,7 +29,7 @@ def run(self):
3829
instead you would need to access them safely by dict.get('...').
3930
"""
4031
# TODO Some cache stuff here
41-
raw = self.get_token()
32+
raw = self.get_token() # TODO: Support policy
4233
if 'error' in raw:
4334
raise MsalServiceError(**raw)
4435
# TODO: Deal with refresh_token

0 commit comments

Comments
 (0)