silentLogin method

  1. @override
Future<void> silentLogin()
override

Attempts to perform a silent login using a previously stored token response obtained from the storageProvider. Throws an error if the silent login fails. Use a try-catch block and call login() in the catch block to open the authentication page for the user.

Implementation

@override
Future<void> silentLogin() async {
  String? savedTokenResponseString =
      await _storageProvider.readTokenResponse();

  await _authenticatorProvider.authorize(
      tokenResponseString: savedTokenResponseString);

  // tries to refresh the token if expired if not expired it returns the token
  final TokenResponse? tokenResponse =
      await _authenticatorProvider.getTokenResponse();

  // if we dont have token even after silent refresh, show login screen
  if (tokenResponse == null) {
    throw 'Silent login failed. `AuthenticatorProvider` failed to create `Credentials using saved token`. Call `login()` to open authentication page';
  }
}