getAccessToken method
Exchanges the authorization code for an access token.
code
: The authorization code obtained during the authentication process.
Returns a String representing the access token.
Implementation
Future<String?> getAccessToken(String code) async {
try {
const String url = "/idshub/token";
var data = {
'redirect_uri': _redirectUri,
'client_id': _clientId,
'client_secret': _clientSecrete,
'grant_type': 'authorization_code',
'code': code
};
final response = await http.post(
Uri.parse(Const.baseUrl(_isProduction) + url),
headers: <String, String>{
'Content-Type': 'application/x-www-form-urlencoded',
},
body: data,
);
if (response.statusCode == 200) {
return UAEPASSUserToken.fromJson(jsonDecode(response.body)).accessToken;
} else {
return null;
}
} catch (e, s) {
if (kDebugMode) {
print(e);
print(s);
}
}
return null;
}