getTokensFromExternalBrowser method

Future<AuthorizationTokenResponse> getTokensFromExternalBrowser({
  1. required String clientID,
  2. required AuthEndpointsData authEndpointsData,
  3. Duration timeout = const Duration(seconds: 45),
})

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.

Implementation

Future<AuthorizationTokenResponse> getTokensFromExternalBrowser({
  required String clientID,
  required AuthEndpointsData authEndpointsData,
  Duration timeout = const Duration(seconds: 45),
}) async {
  final authCodeGrant = _authHelper.getAuthorizeCodeGrant(
    clientID: clientID,
    tokenEndpoint: authEndpointsData.tokenEndpoint,
    authEndpoint: authEndpointsData.authEndpoint,
  );

  final Uri authUrl = _authHelper.getAuthUrl(
    grant: authCodeGrant,
    redirectUrl: authEndpointsData.redirectUrl,
    scopes: authEndpointsData.scopes,
  );

  await _launchAuthUrlWithExternalBrowser(
    authUrl: authUrl,
  ).timeout(timeout, onTimeout: _onTimeout);
  final uri = await _getAppLinkSubscriptionOnUri(
    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,
  );

  return _authHelper.getAuthTokenResponseFromClient(client);
}