@@ -36,11 +36,11 @@ class RedirectUriError(ValueError):
36
36
class _CallbackData :
37
37
def __init__ (self ):
38
38
self .signal = Event ()
39
- self .auth_result = None
39
+ self .result = None
40
40
41
- def complete (self , auth_result ):
41
+ def complete (self , result ):
42
42
self .signal .set ()
43
- self .auth_result = auth_result
43
+ self .result = result
44
44
45
45
46
46
def _convert_error (error , client_id ):
@@ -62,15 +62,16 @@ def _convert_error(error, client_id):
62
62
63
63
64
64
def _read_account_by_id (account_id , correlation_id ):
65
- """Return the callback result which contains the account or error """
65
+ """Return an instance of MSALRuntimeError or MSALRuntimeAccount, or None """
66
66
callback_data = _CallbackData ()
67
67
pymsalruntime .read_account_by_id (
68
68
account_id ,
69
69
correlation_id ,
70
70
lambda result , callback_data = callback_data : callback_data .complete (result )
71
71
)
72
72
callback_data .signal .wait ()
73
- return callback_data .auth_result
73
+ return (callback_data .result .get_error () or callback_data .result .get_account ()
74
+ or None ) # None happens when the account was not created by broker
74
75
75
76
76
77
def _convert_result (result , client_id ): # Mimic an on-the-wire response from AAD
@@ -114,7 +115,7 @@ def _signin_silently(authority, client_id, scopes, correlation_id=None, claims=N
114
115
correlation_id or _get_new_correlation_id (),
115
116
lambda result , callback_data = callback_data : callback_data .complete (result ))
116
117
callback_data .signal .wait ()
117
- return _convert_result (callback_data .auth_result , client_id )
118
+ return _convert_result (callback_data .result , client_id )
118
119
119
120
120
121
def _signin_interactively (
@@ -154,17 +155,16 @@ def _signin_interactively(
154
155
login_hint , # None value will be accepted since pymsalruntime 0.3+
155
156
lambda result , callback_data = callback_data : callback_data .complete (result ))
156
157
callback_data .signal .wait ()
157
- return _convert_result (callback_data .auth_result , client_id )
158
+ return _convert_result (callback_data .result , client_id )
158
159
159
160
160
161
def _acquire_token_silently (
161
162
authority , client_id , account_id , scopes , claims = None , correlation_id = None ):
162
163
correlation_id = correlation_id or _get_new_correlation_id ()
163
164
account = _read_account_by_id (account_id , correlation_id )
164
- error = account .get_error ()
165
- if error :
166
- return _convert_error (error , client_id )
167
- if not account .get_account (): # It happens when the account was not created by broker
165
+ if isinstance (account , pymsalruntime .MSALRuntimeError ):
166
+ return _convert_error (account , client_id )
167
+ if account is None :
168
168
return
169
169
params = pymsalruntime .MSALRuntimeAuthParameters (client_id , authority )
170
170
params .set_requested_scopes (scopes )
@@ -174,10 +174,10 @@ def _acquire_token_silently(
174
174
pymsalruntime .acquire_token_silently (
175
175
params ,
176
176
correlation_id ,
177
- account . get_account () ,
177
+ account ,
178
178
lambda result , callback_data = callback_data : callback_data .complete (result ))
179
179
callback_data .signal .wait ()
180
- return _convert_result (callback_data .auth_result , client_id )
180
+ return _convert_result (callback_data .result , client_id )
181
181
182
182
183
183
def _acquire_token_interactively (
@@ -195,9 +195,10 @@ def _acquire_token_interactively(
195
195
raise NotImplementedError ("We ended up not currently using this function" )
196
196
correlation_id = correlation_id or _get_new_correlation_id ()
197
197
account = _read_account_by_id (account_id , correlation_id )
198
- error = account .get_error ()
199
- if error :
200
- return _convert_error (error , client_id )
198
+ if isinstance (account , pymsalruntime .MSALRuntimeError ):
199
+ return _convert_error (account , client_id )
200
+ if account is None :
201
+ return
201
202
params = pymsalruntime .MSALRuntimeAuthParameters (client_id , authority )
202
203
params .set_requested_scopes (scopes )
203
204
params .set_redirect_uri ("placeholder" ) # pymsalruntime 0.1 requires non-empty str,
@@ -212,8 +213,27 @@ def _acquire_token_interactively(
212
213
window or pymsalruntime .get_console_window () or pymsalruntime .get_desktop_window (), # Since pymsalruntime 0.2+
213
214
params ,
214
215
correlation_id ,
215
- account . get_account () ,
216
+ account ,
216
217
lambda result , callback_data = callback_data : callback_data .complete (result ))
217
218
callback_data .signal .wait ()
218
- return callback_data .auth_result
219
+ return callback_data .result
220
+
221
+
222
+ def _signout_silently (client_id , account_id , correlation_id = None ):
223
+ correlation_id = correlation_id or _get_new_correlation_id ()
224
+ account = _read_account_by_id (account_id , correlation_id )
225
+ if isinstance (account , pymsalruntime .MSALRuntimeError ):
226
+ return _convert_error (account , client_id )
227
+ if account is None :
228
+ return
229
+ callback_data = _CallbackData ()
230
+ pymsalruntime .signout_silently ( # New in PyMsalRuntime 0.7
231
+ client_id ,
232
+ correlation_id ,
233
+ account ,
234
+ lambda result , callback_data = callback_data : callback_data .complete (result ))
235
+ callback_data .signal .wait ()
236
+ error = callback_data .result .get_error ()
237
+ if error :
238
+ return _convert_error (error , client_id )
219
239
0 commit comments