fetchToken method
Fetches a new token and saves it in the storage
Implementation
Future<AccessTokenResponse> fetchToken() async {
_validateAuthorizationParams();
AccessTokenResponse tknResp;
if (grantType == AUTHORIZATION_CODE) {
tknResp = await client.getTokenWithAuthCodeFlow(
clientId: clientId,
clientSecret: clientSecret,
scopes: scopes,
enablePKCE: enablePKCE,
enableState: enableState,
authCodeParams: authCodeParams,
accessTokenParams: accessTokenParams,
afterAuthorizationCodeCb: afterAuthorizationCodeCb,
webAuthClient: webAuthClient,
webAuthOpts: webAuthOpts);
} else if (grantType == CLIENT_CREDENTIALS) {
tknResp = await client.getTokenWithClientCredentialsFlow(
clientId: clientId,
//The clientSecret param can't be null at this point... It has been validated by the above _validateAuthorizationParams call...
clientSecret: clientSecret!,
scopes: scopes);
} else if (grantType == IMPLICIT_GRANT) {
tknResp = await client.getTokenWithImplicitGrantFlow(
clientId: clientId,
scopes: scopes,
enableState: enableState,
webAuthClient: webAuthClient,
webAuthOpts: webAuthOpts,
customParams: authCodeParams);
} else {
tknResp = AccessTokenResponse.errorResponse();
}
if (tknResp.isValid()) {
await tokenStorage.addToken(tknResp);
}
return tknResp;
}