fetchTokenByAuthorizationCode function
Fetch token using the authorization code.
Implementation
Future<LogtoCodeTokenResponse> fetchTokenByAuthorizationCode(
{required http.Client httpClient,
required String tokenEndPoint,
required String code,
required String codeVerifier,
required String clientId,
required String redirectUri,
String? resource}) async {
Map<String, dynamic> payload = {
'grant_type': authorizationCodeGrantType,
'code': code,
'code_verifier': codeVerifier,
'client_id': clientId,
'redirect_uri': redirectUri,
};
if (resource != null && resource.isNotEmpty) {
payload.addAll({'resource': resource});
}
final response = await httpClient.post(Uri.parse(tokenEndPoint),
headers: {'Content-Type': _requestContentType}, body: payload);
var body = httpResponseHandler(response);
return LogtoCodeTokenResponse.fromJson(body);
}