signIn method
Implementation
Future<UserSession> signIn({
required String clientID,
required DioClient microsoftDioClient,
required AuthEndpointsData authEndpointsData,
bool useExternalBrowserOnAndroid = true,
Duration timeout = const Duration(seconds: 15),
Options? getUserDetailsOptions,
}) async {
AuthorizationTokenResponse? response;
// Double check that on login the user data is cleaned out
await SecuredStorage().deleteAuthSessionTokensAndCredentials();
if (!kIsWeb && useExternalBrowserOnAndroid && Platform.isAndroid) {
///This code is for using the system browser instead of the in app web view (custom chrome tab).
///This is necessary, because on the SOTI managed devices,
/// the cache of the custom chrome tab is not cleared after logout from the MUA app.
final AuthorizationCodeGrant authCodeGrant = getAuthorizeCodeGrant(
tokenEndpoint: authEndpointsData.tokenEndpoint,
clientID: clientID,
authEndpoint: authEndpointsData.authEndpoint,
);
final Uri authUrl = getAuthUrl(
grant: authCodeGrant,
redirectUrl: authEndpointsData.redirectUrl,
scopes: authEndpointsData.scopes,
);
await launchAuthUrlWithExternalBrowser(
authUrl: authUrl,
).timeout(timeout, onTimeout: _onTimeout);
final Uri? uri = await _getIndustrialUri(
grant: authCodeGrant,
redirectUrl: authEndpointsData.redirectUrl,
).timeout(timeout, onTimeout: _onTimeout);
if (uri == null) {
throw SessionException(message: 'No data received from the browser');
}
final client = await authCodeGrant.handleAuthorizationResponse(
uri.queryParameters,
);
response = getAuthorizationTokenResponse(client);
}
return await authenticate(
tokenResponse: response,
clientID: clientID,
microsoftDioClient: microsoftDioClient,
authEndpointsData: authEndpointsData,
getUserDetailsOptions: getUserDetailsOptions,
);
}