Skip to content

Keycloak authorization: [Error: Data intent is null] #958

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

Closed
appdeveloper9is opened this issue Apr 6, 2024 · 3 comments
Closed

Keycloak authorization: [Error: Data intent is null] #958

appdeveloper9is opened this issue Apr 6, 2024 · 3 comments
Labels
needs-triage Waiting for a member of the team to confirm

Comments

@appdeveloper9is
Copy link

appdeveloper9is commented Apr 6, 2024

Issue

When user is authenticated, its redirected back to app and it show this error [Error: Data intent is null]. I am currently using schemes.
When it comes back to app it shows nothing in console.log and this error comes which i mentioned above.

App,js :

const config = {
issuer: 'http://domain.com/realms/NewWorld',
clientId: 'Check',
redirectUrl: 'com.myapp://*',
serviceConfiguration: {
authorizationEndpoint: http://domain.com/realms/NewWorld/protocol/openid-connect/auth,
tokenEndpoint: http://domain.com/realms/NewWorld/protocol/openid-connect/token,

},

scopes: ['openid', 'profile', 'email', 'offline_access'],
};
const App = () => {
const handleLogin = async () => {
try {
const authState = await authorize(config);

  console.log("auth", authState);
  // Hantera inloggad användare här
} catch (error) {
  console.log("error",error);
}

};

return (

Login with Keycloak


);
};

Android Manifest :

<uses-permission android:name="android.permission.INTERNET" />

<application
  android:name=".MainApplication"
  android:label="@string/app_name"
  android:icon="@mipmap/ic_launcher"
  android:roundIcon="@mipmap/ic_launcher_round"
  android:allowBackup="false"
  android:theme="@style/AppTheme">
  <activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
    android:launchMode="singleTask"
    android:windowSoftInputMode="adjustResize"
    android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
       <intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />

    <!-- must start with example://main/ -->
    <!-- http://test.example.com/ won't work since http is in a different intent-filter -->
    <data android:scheme="com.myapp"
       
       />

</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="com.myapp"  />
</intent-filter>

In build.gradle file :

manifestPlaceholders = [
         appAuthRedirectScheme: 'com.myapp.auth'
        ]

my keycloak website configuration:

Screenshot 2024-04-07 021632

Environment

  • **Your Identity Provider : Keycloak
  • Platform that you're experiencing the issue on: Android
  • Your react-native Version: e.g. 0.73.5
  • Your react-native-app-auth Version: e.g. 7.1.3
  • **Are you using Expo? No

@varandriy
Copy link

Have the same error

@carbonrobot carbonrobot added the needs-triage Waiting for a member of the team to confirm label May 2, 2024
@faizplus faizplus assigned faizplus and unassigned faizplus May 6, 2024
@fant0mex
Copy link

Hi @appdeveloper9is, seems this has been a long running issue. Can I ask if you have tried any of the solutions from this thread?

@pappebury
Copy link

I found a solution to this issue after following the advice of #494 and #986 issues.
It seems like I failed to understand that the default scheme of the app is sort of an "endpoint" and that a new "endpoint" should be created for the authentication process.
Both "endpoints" will open the app but only one of them is expecting the auth data.

This meant that for a scheme com.myapp you should create a com.myapp.auth scheme by adding it to the build.grade:

android {
    defaultConfig {
        manifestPlaceholders = [
          appAuthRedirectScheme: 'com.myapp.auth'
        ]
    }
}

Then on the config, you would need to point to this new auth scheme:

const config = {
    ...,
    redirectUrl: 'com.myapp.auth://*',
},

Finally on Keycloak you would need to change Valid Redirect URI and Valid post logout redirect URIs to com.myapp.auth so that it points to the "endpoint" that expects the results instead of the main application.

image

Finally you shouldn't need to modify the default Android Manifest file since it already has it's default scheme set up. Adding anything here would result on a prompt making you choose between the different schemes within the app.

@carbonrobot carbonrobot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage Waiting for a member of the team to confirm
Projects
None yet
Development

No branches or pull requests

6 participants