authorizeFromCallback method
Implementation
@override
Future<AuthResult?> authorizeFromCallback(String callbackUrl) async {
final parsed = Uri.parse(callbackUrl);
final code = parsed.queryParameters['code'] as String;
final state = parsed.queryParameters['state'] as String;
log(code);
log(state);
if (this.state == state) {
final res = await _post(
_accessTokenPath,
{
'client_id': clientId,
'client_secret': clientSecret,
'code': code,
'redirect_uri': redirectUri,
},
);
if (res == null) throw Exception("Couldn't authroize");
final decodedRes = json.decode(res);
return AuthResult(
accessToken: decodedRes['access_token'],
);
} else {
throw Exception("Couldn't authroize, the state recieved by GitHub "
"doesn't match state used to authorize.");
}
}