@@ -80,7 +80,7 @@ def _read_account_by_id(account_id, correlation_id):
80
80
or None ) # None happens when the account was not created by broker
81
81
82
82
83
- def _convert_result (result , client_id ): # Mimic an on-the-wire response from AAD
83
+ def _convert_result (result , client_id , expected_token_type = None ): # Mimic an on-the-wire response from AAD
84
84
error = result .get_error ()
85
85
if error :
86
86
return _convert_error (error , client_id )
@@ -95,8 +95,11 @@ def _convert_result(result, client_id): # Mimic an on-the-wire response from AA
95
95
"id_token_claims" : id_token_claims ,
96
96
"client_info" : account .get_client_info (),
97
97
"_account_id" : account .get_account_id (),
98
- "token_type" : "Bearer" , # Hardcoded, for now. It is unavailable from broker.
98
+ "token_type" : expected_token_type or "Bearer" , # Workaround its absence from broker
99
99
}.items () if v }
100
+ likely_a_cert = return_value ["access_token" ].startswith ("AAAA" ) # Empirical observation
101
+ if return_value ["token_type" ].lower () == "ssh-cert" and not likely_a_cert :
102
+ logger .warn ("Looks like we could not get an SSH Cert" )
100
103
granted_scopes = result .get_granted_scopes () # New in pymsalruntime 0.3.x
101
104
if granted_scopes :
102
105
return_value ["scope" ] = " " .join (granted_scopes ) # Mimic the on-the-wire data format
@@ -130,7 +133,8 @@ def _signin_silently(
130
133
correlation_id or _get_new_correlation_id (),
131
134
lambda result , callback_data = callback_data : callback_data .complete (result ))
132
135
callback_data .signal .wait ()
133
- return _convert_result (callback_data .result , client_id )
136
+ return _convert_result (
137
+ callback_data .result , client_id , expected_token_type = kwargs .get ("token_type" ))
134
138
135
139
136
140
def _signin_interactively (
@@ -173,11 +177,13 @@ def _signin_interactively(
173
177
login_hint , # None value will be accepted since pymsalruntime 0.3+
174
178
lambda result , callback_data = callback_data : callback_data .complete (result ))
175
179
callback_data .signal .wait ()
176
- return _convert_result (callback_data .result , client_id )
180
+ return _convert_result (
181
+ callback_data .result , client_id , expected_token_type = kwargs .get ("token_type" ))
177
182
178
183
179
184
def _acquire_token_silently (
180
- authority , client_id , account_id , scopes , claims = None , correlation_id = None ):
185
+ authority , client_id , account_id , scopes , claims = None , correlation_id = None ,
186
+ ** kwargs ):
181
187
correlation_id = correlation_id or _get_new_correlation_id ()
182
188
account = _read_account_by_id (account_id , correlation_id )
183
189
if isinstance (account , pymsalruntime .MSALRuntimeError ):
@@ -188,14 +194,18 @@ def _acquire_token_silently(
188
194
params .set_requested_scopes (scopes )
189
195
if claims :
190
196
params .set_decoded_claims (claims )
197
+ for k , v in kwargs .items (): # This can be used to support domain_hint, max_age, etc.
198
+ if v is not None :
199
+ params .set_additional_parameter (k , str (v ))
191
200
callback_data = _CallbackData ()
192
201
pymsalruntime .acquire_token_silently (
193
202
params ,
194
203
correlation_id ,
195
204
account ,
196
205
lambda result , callback_data = callback_data : callback_data .complete (result ))
197
206
callback_data .signal .wait ()
198
- return _convert_result (callback_data .result , client_id )
207
+ return _convert_result (
208
+ callback_data .result , client_id , expected_token_type = kwargs .get ("token_type" ))
199
209
200
210
201
211
def _acquire_token_interactively (
0 commit comments