2

I am using AppAuth library for Oauth2 authentication. https://github.com/openid/AppAuth-Android

I am using google's app auth example. https://codelabs.developers.google.com/codelabs/appauth-android-codelab/#0

I modified the urls as per my oauth provider. I have specified a valid authorization endpoint, client id, redirect uri, token uri, scope(openid, profile, email), response type (Code). I don't know if there is a way to add consumer secret. I have not seen anywhere in the sample code a way to add consumer secret. When I run the app, I see our sso page, I am able to login, redirect happens. When the request to get token gets executed, I get an exception. The token request is failing. Any idea why this would happen? The token exchange url is correct and I am not sure why it is complaining about file not being found at that particular token url. Any pointers on digging more into this issue?

W/AppAuthSample: Token Exchange failed
    AuthorizationException: {"type":0,"code":3,"errorDescription":"Network error"}
        at net.openid.appauth.AuthorizationService$TokenRequestTask.doInBackground(AuthorizationService.java:244)
        at net.openid.appauth.AuthorizationService$TokenRequestTask.doInBackground(AuthorizationService.java:206)
        at android.os.AsyncTask$2.call(AsyncTask.java:333)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)
     Caused by: java.io.FileNotFoundException: <token_url>
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:251)
        at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)
        at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:26)
        at net.openid.appauth.AuthorizationService$TokenRequestTask.doInBackground(AuthorizationService.java:239)
        at net.openid.appauth.AuthorizationService$TokenRequestTask.doInBackground(AuthorizationService.java:206) 
        at android.os.AsyncTask$2.call(AsyncTask.java:333) 
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:764) 
Karu
  • 935
  • 2
  • 13
  • 32

1 Answers1

0

Are you using the emulator by any chance? I had the exact same issue. For the emulator, the local host is 10.0.0.2 so changed the authorization and token endpoints to use that.

However, it seems that for the token endpoint, it should be localhost after all.

So my final serviceConfiguration looks like:

AuthorizationServiceConfiguration serviceConfiguration = new AuthorizationServiceConfiguration(
        Uri.parse("http://10.0.2.2:8080/oauth/authorize"), // authorization endpoint (localhost endpoint)
        Uri.parse("http://localhost:8080/oauth/token") // token endpoint (localhost endpoint)
);

Hope that helps.

The reason for java.io.FileNotFoundException is that the http response code is 400 or more so definitely a problem with the url as is shown here

Syntax
  • 111
  • 6