Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File not found exception when requesting token #436

Closed
karunanaik opened this issue Dec 5, 2018 · 6 comments
Closed

File not found exception when requesting token #436

karunanaik opened this issue Dec 5, 2018 · 6 comments

Comments

@karunanaik
Copy link

I am using the google app auth example. I modified the urls as per my oauth provider.
I have specified the 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) 
@karunanaik
Copy link
Author

I updated the demo app to using android x. I am also using the latest library version. The build is fine. I am able to see the sso page. I can login but the redirect does not happen as expected.
This is how my build.gradle looks like.
apply plugin: 'com.android.application'


android {
    compileSdkVersion 28

    defaultConfig {
        applicationId "com.google.codelabs.appauth"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        android.defaultConfig.manifestPlaceholders = [
                'appAuthRedirectScheme': 'mdconnect'
        ]
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    testImplementation 'junit:junit:4.12'
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.squareup.retrofit2:retrofit:2.1.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.9.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
    implementation 'net.openid:appauth:0.7.1'
}

This is a snippet of my manifest.xml

<manifest package="com.google.codelabs.appauth"
          xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:name=".MainApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
            <intent-filter>
                <action android:name="mdconnect.HANDLE_AUTHORIZATION_RESPONSE"/>
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
        </activity>

        <activity android:name="net.openid.appauth.RedirectUriReceiverActivity">
            <intent-filter>
                <action android:name="android.intent.action.VIEW"/>

                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE"/>

                <data android:scheme="mdconnect"/>
            </intent-filter>
        </activity>
    </application>
</manifest>

@iainmcgin
Copy link
Member

You'll get a FileNotFoundException if the server responds with a 404 response code for your token URL. Please check again that you have specified the right token endpoint for the IDP you are integrating with.

@Johnnie843
Copy link

Im getting the same error but I'm using my own keycloak server. I get the SSO login screen but when it does the callback I get:

06-17 02:15:42.500 26098-26098/com.google.codelabs.appauth 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:292)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)

I check the Auth and Token URI and they are correct and on the keycloak server I see I have active session with my login.

@Johnnie843
Copy link

@iainmcgin

@essieM
Copy link

essieM commented Apr 5, 2020

@Johnnie843 were you able to resolve this issue? I'm also getting the same error with my Keycloak server.

@hb0
Copy link

hb0 commented May 22, 2023

Just for future readers: FileNotFoundException also occurs when client_id is not set in the client.

(When using Keycloak)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants