Skip to content

Commit 0cf8686

Browse files
committed
Fix Azure v2 profile method
1 parent 0b53547 commit 0cf8686

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

loginpass/azure.py

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,33 @@ def create_azure_backend(name, tenant, version=1, claims_options=None):
1818
authorize_url = '{}{}/oauth2/authorize'.format(_BASE_URL, tenant)
1919
token_url = '{}{}/oauth2/token'.format(_BASE_URL, tenant)
2020
issuer_url = 'https://sts.windows.net/{}/'.format(tenant)
21+
if claims_options is None:
22+
claims_options = {
23+
'iss': {
24+
'values': [issuer_url]
25+
}
26+
}
27+
2128
elif version == 2:
2229
authorize_url = '{}{}/oauth2/v2.0/authorize'.format(_BASE_URL, tenant)
2330
token_url = '{}{}/oauth2/v2.0/token'.format(_BASE_URL, tenant)
2431
issuer_url = '{}{}/v2.0'.format(_BASE_URL, tenant)
25-
else:
26-
raise ValueError('Invalid version')
2732

28-
if claims_options is None:
29-
claims_options = {
30-
"iss": {
31-
"values": [issuer_url]
33+
if claims_options is None:
34+
35+
def validate_iss(claims, value):
36+
iss = 'https://login.microsoftonline.com/{}/v2.0'.format(claims['tid'])
37+
return iss == value
38+
39+
claims_options = {
40+
'iss': {
41+
'essential': True,
42+
'validate': validate_iss,
43+
}
3244
}
33-
}
45+
46+
else:
47+
raise ValueError('Invalid version')
3448

3549
class AzureAD(OAuthBackend):
3650
OAUTH_TYPE = '2.0,oidc'
@@ -55,7 +69,16 @@ def parse_openid(self, token, nonce=None):
5569
token.get('access_token'), nonce
5670
)
5771

58-
return AzureAD
72+
class AzureADv2(AzureAD):
73+
JWK_SET_URL = '{}{}/discovery/v2.0/keys'.format(_BASE_URL, tenant)
74+
75+
def profile(self, **kwargs):
76+
return self.parse_openid(**kwargs)
77+
78+
if version == 2:
79+
return AzureADv2
80+
else:
81+
return AzureAD
5982

6083

6184
Azure = create_azure_backend('azure', 'common')

0 commit comments

Comments
 (0)