performAuthenticate method

  1. @override
Future<Account?> performAuthenticate()
override

This method is for subclasses only. Call authenticate() instead.

Implementation

@override
Future<Account?> performAuthenticate() async {
  BasicAuthAccount? account =
      currentBasicAccount ?? await loadAccountFromCache<BasicAuthAccount>();
  if (account?.isValid() ?? false) {
    return currentAccount = account;
  }
  BasicAuthAuthenticator authenticator = getAuthenticator()!;
  await authenticator.resetAuthenticator();

  if (showAuthenticator != null)
    showAuthenticator!(authenticator);
  else if (sharedShowAuthenticator != null)
    sharedShowAuthenticator!(authenticator);
  else
    throw new Exception(
        "Please call `SimpleAuthFlutter.init();` or implement the 'showAuthenticator' or 'sharedShowAuthenticator'");
  var token = await authenticator.getAuthCode();
  if (token.isEmpty) {
    throw new Exception("Null Token");
  }
  account = new BasicAuthAccount(identifier, key: token);
  saveAccountToCache(account);
  currentAccount = account;
  return account;
}