I am setting up my android application to use authentication and I am following the documentation on AppAuth for Android. So far I have been able to connect and make a request to the identity server and gotten back a response containing most of data I sent in my request and more. I am supposed to exchange my code for an access token. This is my problem. I'm literally copying and pasting the code on the github page,https://github.com/openid/AppAuth-Android, yet it is crashing with the above error. I am relatively new to android and this is my first question here, go easy on me if I am not presenting my question well. Thank you.
Android Studio says the code causing this error is "authService.performTokenRequest()". I have looked around and some solved it by calling "authService.dispose()" in "onDestroy()" but that also crashes with "An error occured while executing doInBackground()". Below is the code causing the error.
authService.performTokenRequest(
resp.createTokenExchangeRequest(),
new AuthorizationService.TokenResponseCallback() {
@Override public void onTokenRequestCompleted(
TokenResponse resp, AuthorizationException ex) {
if (resp != null) {
// exchange succeeded
} else {
// authorization failed, check ex for more details
}
}
});
In my "onCreate()" this is how I call it.
AuthorizationResponse resp = AuthorizationResponse.fromIntent(getIntent());
AuthorizationException ex = AuthorizationException.fromIntent(getIntent());
authState = new AuthState(resp, ex);
authorizationService = new AuthorizationService(this);
authorizationService.performTokenRequest(
resp.createTokenExchangeRequest(),
new AuthorizationService.TokenResponseCallback() {
@Override public void onTokenRequestCompleted(
TokenResponse resp, AuthorizationException ex) {
authState.update(resp, ex);
if (resp != null) {
// exchange succeeded
Log.e("authstate",authState.getAccessToken());
} else {
// authorization failed, check ex for more details
}
}
});
You can dispose your authService onDestroy(). for example you have
AuthorizationService mAuthService = new AuthorizationService(context);
@Override
protected void onDestroy() {
mAuthService.dispose();
mAuthService = null;
}