getTokenResponse method
Implementation
Future<TokenResponse> getTokenResponse([bool forceRefresh = false]) async {
if (!forceRefresh &&
_token.accessToken != null &&
_token.expiresAt!.isAfter(DateTime.now())) {
return _token;
}
if (_token.accessToken == null && _token.refreshToken == null) {
return _token;
}
var json = await http.post(client!.issuer!.metadata.tokenEndpoint,
body: {
'grant_type': 'refresh_token',
'refresh_token': _token.refreshToken,
'client_id': client!.clientId,
if (client!.clientSecret != null)
'client_secret': client!.clientSecret
},
client: client!.httpClient);
if (json['error'] != null) {
throw OpenIdException(
json['error'], json['error_description'], json['error_uri']);
}
return _token = TokenResponse.fromJson(json);
}