exchangeCode static method
Future<Either<GoogleAuthFailure, GoogleTokens> >
exchangeCode(
- GoogleTokenExchangerInputModel googleTokenExchangerInputModel
exchange authorization code for access token
Implementation
static Future<Either<GoogleAuthFailure, GoogleTokens>> exchangeCode(
GoogleTokenExchangerInputModel googleTokenExchangerInputModel,
) async {
final response = await post(
Uri.parse(googleTokenExchangerInputModel.apiUrl),
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: {
"code": googleTokenExchangerInputModel.code,
"client_id": googleTokenExchangerInputModel.clientId,
"client_secret": googleTokenExchangerInputModel.clientSecret,
"redirect_uri": googleTokenExchangerInputModel.redirectUri,
"code_verifier": googleTokenExchangerInputModel.codeVerifier,
"grant_type": googleTokenExchangerInputModel.grantType,
},
);
if (response.statusCode != 200) {
return left(GoogleAuthFailure(message: ""));
}
final data = jsonDecode(response.body) as Map<String, dynamic>;
return right(
GoogleTokens(
idToken: data["id_token"],
accessToken: data["access_token"],
),
);
}