FormidableLabs / react-native-app-auth

React native bridge for AppAuth - an SDK for communicating with OAuth2 providers
https://commerce.nearform.com/open-source/react-native-app-auth
MIT License
2.04k stars 441 forks source link

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

Closed appdeveloper9is closed 1 month ago

appdeveloper9is commented 7 months ago

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
varandriy commented 7 months ago

Have the same error

fant0mex commented 6 months ago

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 commented 1 month ago

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.