@@ -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 = {
@@ -987,7 +993,7 @@ def acquire_token_by_refresh_token(self, refresh_token, scopes, **kwargs):
987
993
* A dict contains no "error" key means migration was successful.
988
994
"""
989
995
self ._validate_ssh_cert_input_data (kwargs .get ("data" , {}))
990
- return self .client .obtain_token_by_refresh_token (
996
+ return _clean_up ( self .client .obtain_token_by_refresh_token (
991
997
refresh_token ,
992
998
scope = decorate_scope (scopes , self .client_id ),
993
999
headers = {
@@ -998,7 +1004,7 @@ def acquire_token_by_refresh_token(self, refresh_token, scopes, **kwargs):
998
1004
rt_getter = lambda rt : rt ,
999
1005
on_updating_rt = False ,
1000
1006
on_removing_rt = lambda rt_item : None , # No OP
1001
- ** kwargs )
1007
+ ** kwargs ))
1002
1008
1003
1009
1004
1010
class PublicClientApplication (ClientApplication ): # browser app or mobile app
@@ -1072,7 +1078,7 @@ def acquire_token_interactive(
1072
1078
self ._validate_ssh_cert_input_data (kwargs .get ("data" , {}))
1073
1079
claims = _merge_claims_challenge_and_capabilities (
1074
1080
self ._client_capabilities , claims_challenge )
1075
- return self .client .obtain_token_by_browser (
1081
+ return _clean_up ( self .client .obtain_token_by_browser (
1076
1082
scope = decorate_scope (scopes , self .client_id ) if scopes else None ,
1077
1083
extra_scope_to_consent = extra_scopes_to_consent ,
1078
1084
redirect_uri = "http://localhost:{port}" .format (
@@ -1091,7 +1097,7 @@ def acquire_token_interactive(
1091
1097
CLIENT_CURRENT_TELEMETRY : _build_current_telemetry_request_header (
1092
1098
self .ACQUIRE_TOKEN_INTERACTIVE ),
1093
1099
},
1094
- ** kwargs )
1100
+ ** kwargs ))
1095
1101
1096
1102
def initiate_device_flow (self , scopes = None , ** kwargs ):
1097
1103
"""Initiate a Device Flow instance,
@@ -1134,7 +1140,7 @@ def acquire_token_by_device_flow(self, flow, claims_challenge=None, **kwargs):
1134
1140
- A successful response would contain "access_token" key,
1135
1141
- an error response would contain "error" and usually "error_description".
1136
1142
"""
1137
- return self .client .obtain_token_by_device_flow (
1143
+ return _clean_up ( self .client .obtain_token_by_device_flow (
1138
1144
flow ,
1139
1145
data = dict (
1140
1146
kwargs .pop ("data" , {}),
@@ -1150,7 +1156,7 @@ def acquire_token_by_device_flow(self, flow, claims_challenge=None, **kwargs):
1150
1156
CLIENT_CURRENT_TELEMETRY : _build_current_telemetry_request_header (
1151
1157
self .ACQUIRE_TOKEN_BY_DEVICE_FLOW_ID ),
1152
1158
},
1153
- ** kwargs )
1159
+ ** kwargs ))
1154
1160
1155
1161
def acquire_token_by_username_password (
1156
1162
self , username , password , scopes , claims_challenge = None , ** kwargs ):
@@ -1188,15 +1194,15 @@ def acquire_token_by_username_password(
1188
1194
user_realm_result = self .authority .user_realm_discovery (
1189
1195
username , correlation_id = headers [CLIENT_REQUEST_ID ])
1190
1196
if user_realm_result .get ("account_type" ) == "Federated" :
1191
- return self ._acquire_token_by_username_password_federated (
1197
+ return _clean_up ( self ._acquire_token_by_username_password_federated (
1192
1198
user_realm_result , username , password , scopes = scopes ,
1193
1199
data = data ,
1194
- headers = headers , ** kwargs )
1195
- return self .client .obtain_token_by_username_password (
1200
+ headers = headers , ** kwargs ))
1201
+ return _clean_up ( self .client .obtain_token_by_username_password (
1196
1202
username , password , scope = scopes ,
1197
1203
headers = headers ,
1198
1204
data = data ,
1199
- ** kwargs )
1205
+ ** kwargs ))
1200
1206
1201
1207
def _acquire_token_by_username_password_federated (
1202
1208
self , user_realm_result , username , password , scopes = None , ** kwargs ):
@@ -1256,7 +1262,7 @@ def acquire_token_for_client(self, scopes, claims_challenge=None, **kwargs):
1256
1262
"""
1257
1263
# TBD: force_refresh behavior
1258
1264
self ._validate_ssh_cert_input_data (kwargs .get ("data" , {}))
1259
- return self .client .obtain_token_for_client (
1265
+ return _clean_up ( self .client .obtain_token_for_client (
1260
1266
scope = scopes , # This grant flow requires no scope decoration
1261
1267
headers = {
1262
1268
CLIENT_REQUEST_ID : _get_new_correlation_id (),
@@ -1267,7 +1273,7 @@ def acquire_token_for_client(self, scopes, claims_challenge=None, **kwargs):
1267
1273
kwargs .pop ("data" , {}),
1268
1274
claims = _merge_claims_challenge_and_capabilities (
1269
1275
self ._client_capabilities , claims_challenge )),
1270
- ** kwargs )
1276
+ ** kwargs ))
1271
1277
1272
1278
def acquire_token_on_behalf_of (self , user_assertion , scopes , claims_challenge = None , ** kwargs ):
1273
1279
"""Acquires token using on-behalf-of (OBO) flow.
@@ -1297,7 +1303,7 @@ def acquire_token_on_behalf_of(self, user_assertion, scopes, claims_challenge=No
1297
1303
"""
1298
1304
# The implementation is NOT based on Token Exchange
1299
1305
# https://tools.ietf.org/html/draft-ietf-oauth-token-exchange-16
1300
- return self .client .obtain_token_by_assertion ( # bases on assertion RFC 7521
1306
+ return _clean_up ( self .client .obtain_token_by_assertion ( # bases on assertion RFC 7521
1301
1307
user_assertion ,
1302
1308
self .client .GRANT_TYPE_JWT , # IDTs and AAD ATs are all JWTs
1303
1309
scope = decorate_scope (scopes , self .client_id ), # Decoration is used for:
@@ -1316,4 +1322,4 @@ def acquire_token_on_behalf_of(self, user_assertion, scopes, claims_challenge=No
1316
1322
CLIENT_CURRENT_TELEMETRY : _build_current_telemetry_request_header (
1317
1323
self .ACQUIRE_TOKEN_ON_BEHALF_OF_ID ),
1318
1324
},
1319
- ** kwargs )
1325
+ ** kwargs ))
0 commit comments