performAuthenticate method
This method is for subclasses only. Call authenticate() instead.
Implementation
@override
Future<Account?> performAuthenticate() async {
if (scopesRequired && (scopes?.length ?? 0) == 0) {
throw Exception("Scopes are required");
}
OAuthAccount? account =
currentOauthAccount ?? await loadAccountFromCache<OAuthAccount>();
if (account != null &&
((account.refreshToken?.isNotEmpty ?? false) ||
(account.expiresIn != null && account.expiresIn! <= 0))) {
var valid = account.isValid();
if (!valid || forceRefresh) {
//If there is no interent, give them the current expired account
if (!await pingUrl(tokenUrl!)) {
return account;
}
if (await refreshAccount(account))
account = currentOauthAccount ?? loadAccountFromCache<OAuthAccount>() as OAuthAccount;
}
if (account.isValid()) {
saveAccountToCache(account);
currentAccount = account;
return account;
}
}
var _authenticator = getAuthenticator()!;
await _authenticator.resetAuthenticator();
if (showAuthenticator != null)
showAuthenticator!(_authenticator as WebAuthenticator);
else if (sharedShowAuthenticator != null)
sharedShowAuthenticator!(_authenticator as WebAuthenticator);
else
throw new Exception(
"You are required to implement the 'showAuthenticator or sharedShowAuthenticator");
var token = await _authenticator.getAuthCode();
if (token.isEmpty) {
throw new Exception("Null Token");
}
account = await getAccountFromAuthCode(_authenticator);
saveAccountToCache(account);
currentAccount = account;
return account;
}