@@ -100,6 +100,12 @@ def _str2bytes(raw):
100
100
return raw
101
101
102
102
103
+ def _clean_up (result ):
104
+ if isinstance (result , dict ):
105
+ result .pop ("refresh_in" , None ) # MSAL handled refresh_in, customers need not
106
+ return result
107
+
108
+
103
109
class ClientApplication (object ):
104
110
105
111
ACQUIRE_TOKEN_SILENT_ID = "84"
@@ -507,7 +513,7 @@ def authorize(): # A controller in a web app
507
513
return redirect(url_for("index"))
508
514
"""
509
515
self ._validate_ssh_cert_input_data (kwargs .get ("data" , {}))
510
- return self .client .obtain_token_by_auth_code_flow (
516
+ return _clean_up ( self .client .obtain_token_by_auth_code_flow (
511
517
auth_code_flow ,
512
518
auth_response ,
513
519
scope = decorate_scope (scopes , self .client_id ) if scopes else None ,
@@ -521,7 +527,7 @@ def authorize(): # A controller in a web app
521
527
claims = _merge_claims_challenge_and_capabilities (
522
528
self ._client_capabilities ,
523
529
auth_code_flow .pop ("claims_challenge" , None ))),
524
- ** kwargs )
530
+ ** kwargs ))
525
531
526
532
def acquire_token_by_authorization_code (
527
533
self ,
@@ -580,7 +586,7 @@ def acquire_token_by_authorization_code(
580
586
"Change your acquire_token_by_authorization_code() "
581
587
"to acquire_token_by_auth_code_flow()" , DeprecationWarning )
582
588
with warnings .catch_warnings (record = True ):
583
- return self .client .obtain_token_by_authorization_code (
589
+ return _clean_up ( self .client .obtain_token_by_authorization_code (
584
590
code , redirect_uri = redirect_uri ,
585
591
scope = decorate_scope (scopes , self .client_id ),
586
592
headers = {
@@ -593,7 +599,7 @@ def acquire_token_by_authorization_code(
593
599
claims = _merge_claims_challenge_and_capabilities (
594
600
self ._client_capabilities , claims_challenge )),
595
601
nonce = nonce ,
596
- ** kwargs )
602
+ ** kwargs ))
597
603
598
604
def get_accounts (self , username = None ):
599
605
"""Get a list of accounts which previously signed in, i.e. exists in cache.
@@ -855,13 +861,13 @@ def _acquire_token_silent_from_cache_and_possibly_refresh_it(
855
861
result = self ._acquire_token_silent_by_finding_rt_belongs_to_me_or_my_family (
856
862
authority , decorate_scope (scopes , self .client_id ), account ,
857
863
force_refresh = force_refresh , claims_challenge = claims_challenge , ** kwargs )
864
+ result = _clean_up (result )
858
865
if (result and "error" not in result ) or (not access_token_from_cache ):
859
866
return result
860
867
except : # The exact HTTP exception is transportation-layer dependent
861
868
logger .exception ("Refresh token failed" ) # Potential AAD outage?
862
869
return access_token_from_cache
863
870
864
-
865
871
def _acquire_token_silent_by_finding_rt_belongs_to_me_or_my_family (
866
872
self , authority , scopes , account , ** kwargs ):
867
873
query = {
@@ -993,7 +999,7 @@ def acquire_token_by_refresh_token(self, refresh_token, scopes, **kwargs):
993
999
* A dict contains no "error" key means migration was successful.
994
1000
"""
995
1001
self ._validate_ssh_cert_input_data (kwargs .get ("data" , {}))
996
- return self .client .obtain_token_by_refresh_token (
1002
+ return _clean_up ( self .client .obtain_token_by_refresh_token (
997
1003
refresh_token ,
998
1004
scope = decorate_scope (scopes , self .client_id ),
999
1005
headers = {
@@ -1004,7 +1010,7 @@ def acquire_token_by_refresh_token(self, refresh_token, scopes, **kwargs):
1004
1010
rt_getter = lambda rt : rt ,
1005
1011
on_updating_rt = False ,
1006
1012
on_removing_rt = lambda rt_item : None , # No OP
1007
- ** kwargs )
1013
+ ** kwargs ))
1008
1014
1009
1015
1010
1016
class PublicClientApplication (ClientApplication ): # browser app or mobile app
@@ -1081,7 +1087,7 @@ def acquire_token_interactive(
1081
1087
self ._validate_ssh_cert_input_data (kwargs .get ("data" , {}))
1082
1088
claims = _merge_claims_challenge_and_capabilities (
1083
1089
self ._client_capabilities , claims_challenge )
1084
- return self .client .obtain_token_by_browser (
1090
+ return _clean_up ( self .client .obtain_token_by_browser (
1085
1091
scope = decorate_scope (scopes , self .client_id ) if scopes else None ,
1086
1092
extra_scope_to_consent = extra_scopes_to_consent ,
1087
1093
redirect_uri = "http://localhost:{port}" .format (
@@ -1100,7 +1106,7 @@ def acquire_token_interactive(
1100
1106
CLIENT_CURRENT_TELEMETRY : _build_current_telemetry_request_header (
1101
1107
self .ACQUIRE_TOKEN_INTERACTIVE ),
1102
1108
},
1103
- ** kwargs )
1109
+ ** kwargs ))
1104
1110
1105
1111
def initiate_device_flow (self , scopes = None , ** kwargs ):
1106
1112
"""Initiate a Device Flow instance,
@@ -1143,7 +1149,7 @@ def acquire_token_by_device_flow(self, flow, claims_challenge=None, **kwargs):
1143
1149
- A successful response would contain "access_token" key,
1144
1150
- an error response would contain "error" and usually "error_description".
1145
1151
"""
1146
- return self .client .obtain_token_by_device_flow (
1152
+ return _clean_up ( self .client .obtain_token_by_device_flow (
1147
1153
flow ,
1148
1154
data = dict (
1149
1155
kwargs .pop ("data" , {}),
@@ -1159,7 +1165,7 @@ def acquire_token_by_device_flow(self, flow, claims_challenge=None, **kwargs):
1159
1165
CLIENT_CURRENT_TELEMETRY : _build_current_telemetry_request_header (
1160
1166
self .ACQUIRE_TOKEN_BY_DEVICE_FLOW_ID ),
1161
1167
},
1162
- ** kwargs )
1168
+ ** kwargs ))
1163
1169
1164
1170
def acquire_token_by_username_password (
1165
1171
self , username , password , scopes , claims_challenge = None , ** kwargs ):
@@ -1197,15 +1203,15 @@ def acquire_token_by_username_password(
1197
1203
user_realm_result = self .authority .user_realm_discovery (
1198
1204
username , correlation_id = headers [CLIENT_REQUEST_ID ])
1199
1205
if user_realm_result .get ("account_type" ) == "Federated" :
1200
- return self ._acquire_token_by_username_password_federated (
1206
+ return _clean_up ( self ._acquire_token_by_username_password_federated (
1201
1207
user_realm_result , username , password , scopes = scopes ,
1202
1208
data = data ,
1203
- headers = headers , ** kwargs )
1204
- return self .client .obtain_token_by_username_password (
1209
+ headers = headers , ** kwargs ))
1210
+ return _clean_up ( self .client .obtain_token_by_username_password (
1205
1211
username , password , scope = scopes ,
1206
1212
headers = headers ,
1207
1213
data = data ,
1208
- ** kwargs )
1214
+ ** kwargs ))
1209
1215
1210
1216
def _acquire_token_by_username_password_federated (
1211
1217
self , user_realm_result , username , password , scopes = None , ** kwargs ):
@@ -1265,7 +1271,7 @@ def acquire_token_for_client(self, scopes, claims_challenge=None, **kwargs):
1265
1271
"""
1266
1272
# TBD: force_refresh behavior
1267
1273
self ._validate_ssh_cert_input_data (kwargs .get ("data" , {}))
1268
- return self .client .obtain_token_for_client (
1274
+ return _clean_up ( self .client .obtain_token_for_client (
1269
1275
scope = scopes , # This grant flow requires no scope decoration
1270
1276
headers = {
1271
1277
CLIENT_REQUEST_ID : _get_new_correlation_id (),
@@ -1276,7 +1282,7 @@ def acquire_token_for_client(self, scopes, claims_challenge=None, **kwargs):
1276
1282
kwargs .pop ("data" , {}),
1277
1283
claims = _merge_claims_challenge_and_capabilities (
1278
1284
self ._client_capabilities , claims_challenge )),
1279
- ** kwargs )
1285
+ ** kwargs ))
1280
1286
1281
1287
def acquire_token_on_behalf_of (self , user_assertion , scopes , claims_challenge = None , ** kwargs ):
1282
1288
"""Acquires token using on-behalf-of (OBO) flow.
@@ -1306,7 +1312,7 @@ def acquire_token_on_behalf_of(self, user_assertion, scopes, claims_challenge=No
1306
1312
"""
1307
1313
# The implementation is NOT based on Token Exchange
1308
1314
# https://tools.ietf.org/html/draft-ietf-oauth-token-exchange-16
1309
- return self .client .obtain_token_by_assertion ( # bases on assertion RFC 7521
1315
+ return _clean_up ( self .client .obtain_token_by_assertion ( # bases on assertion RFC 7521
1310
1316
user_assertion ,
1311
1317
self .client .GRANT_TYPE_JWT , # IDTs and AAD ATs are all JWTs
1312
1318
scope = decorate_scope (scopes , self .client_id ), # Decoration is used for:
@@ -1325,4 +1331,4 @@ def acquire_token_on_behalf_of(self, user_assertion, scopes, claims_challenge=No
1325
1331
CLIENT_CURRENT_TELEMETRY : _build_current_telemetry_request_header (
1326
1332
self .ACQUIRE_TOKEN_ON_BEHALF_OF_ID ),
1327
1333
},
1328
- ** kwargs )
1334
+ ** kwargs ))
0 commit comments