signOut method
Sign out user and erases associated tokens.
The tag
argument is used to distinguish which invocation of this
function generated the return callback. The subject
is used to specify
the user to authenticate (it corresponds to the
Returns a Future callable from the AzureB2C plugin.
It emits a B2COperationResult from B2COperationSource.SIGN_OUT with possible results:
- B2COperationState.SUCCESS if successful (only in B2CInteractionMode.POPUP mode or it will reload the app if in B2CInteractionMode.REDIRECT mode),
- B2COperationState.CLIENT_ERROR if an error occurred,
Implementation
Future signOut(String tag, String subject) async {
try {
var user = _users[subject];
if (user == null) {
_emitCallback(B2COperationResult(
tag,
B2COperationSource.POLICY_TRIGGER_SILENTLY,
B2COperationState.CLIENT_ERROR));
return;
}
if (_interactionMode == B2CInteractionMode.REDIRECT) {
await _b2cApp!.logoutRedirect(EndSessionRequest()..account = user);
return; //redirect flow will restart the app
} else {
await _b2cApp!.logoutPopup(EndSessionPopupRequest()..account = user);
_users.remove(_getUniqueId(user));
_emitCallback(B2COperationResult(
tag, B2COperationSource.SIGN_OUT, B2COperationState.SUCCESS));
}
} on AuthException {
_emitCallback(B2COperationResult(
tag, B2COperationSource.SIGN_OUT, B2COperationState.CLIENT_ERROR));
}
}