Git Product home page Git Product logo

react-native-keycloak's Introduction

⚠️ DEPRECATED and UNMAINTAINED

This library is deprecated and will no longer be maintained or updated.

Instead, it is recommended to use:



React Keycloak

React Keycloak

React bindings for Keycloak

NPM (scoped) NPM (scoped) NPM (scoped) NPM (scoped)

License lerna GitHub contributors Github Issues npm

Gitter


Table of Contents


Integrations

React

React Keycloak for Web requires:

  • React 16.0 or later
  • keycloak-js 9.0.2 or later
yarn add @react-keycloak/web

or

npm install --save @react-keycloak/web

or as a UMD package through unpkg

See @react-keycloak/web package README for complete documentation.

SSR

React Keycloak for SSR frameworks requires:

  • React 16.0 or later
  • SSR Framework:
    • NextJS 9 or later
    • Razzle 3 or later
  • keycloak-js 9.0.2 or later
yarn add @react-keycloak/ssr

or

npm install --save @react-keycloak/ssr

See @react-keycloak/ssr package README for complete documentation.

React Native

React Keycloak for React Native requires React Native 61.0 or later

To install run

yarn add @react-keycloak/native

or

npm install --save @react-keycloak/native

See @react-keycloak/native package README for complete documentation.

Support

version keycloak-js version
v2.0.0+ 9.0.2+
v1.x >=8.0.2 <9.0.2

Examples

See @react-keycloak/react-keycloak-examples repository for various demo implementing this library main features.

Alternatives

If you need to connect using a more generic OIDC client instead of keycloak.js, consider using one of the following libraries:

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

react-native-keycloak's People

Contributors

dependabot[bot] avatar enlightenedpie avatar glauberbrack avatar irontony avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

react-native-keycloak's Issues

Unable to obtain access token after login

Hi!
After the login method, i receive 3 tokens provided by onTokens handler function:

  • idToken
  • refreshToken
  • token

but no one of these is the access token that i need for authenticate my http calls.

Any suggest?

Thanks

Help

Hello

I still haven't been able to implement it .. I log in and I'm not redirected to the app. can you be more direct in the documentation? so no one will use your library.

thank you.

I tried to login

I tried to Login with the library

environment:

  • "@react-keycloak/native": "^0.2.1"
  • "react-native": "0.63.0"
  • "react": "16.13.1"

const login = () => keycloak?.login()

image

Any idea?

After click the Login Button "Error: InAppBrowser not available"

Hi Team

When i click the login button from simulater I am getting below error

Possible Unhandled Promise Rejection (id: 0):
Error: InAppBrowser not available
login$@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:112920:32
tryCatch@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:112128:23
invoke@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:112298:32
tryCatch@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:112128:23
invoke@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:112200:30
http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:112210:21
tryCallOne@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:29348:16
http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:29449:27
_callTimer@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:32960:17
_callImmediatesPass@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:32996:19
callImmediates@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:33215:33
callImmediates@[native code]
__callImmediates@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:2538:35
http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:2323:34
__guard@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:2521:15
flushedQueue@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:2322:21
flushedQueue@[native code]
invokeCallbackAndReturnFlushedQueue@[native code]

Please see the attached Screen shot. Please help me to resolve this
Capture

Version compatibility

how is the compatibility with class component?

i was facing this problem which i have the version of "react-native": "0.61.2" and "@react-keycloak/native": "^0.5.2" but throws me a warning of promise unhandled.

it It a compatibility problem?

Authorization code (standard) flow not working with PKCE enabled

Describe the bug

  1. I'm using the example found in https://github.com/react-keycloak/react-native-keycloak/tree/master/example and got it working as is with no PKCE
  2. When enabling PKCE i get the error "Missing parameter: code_challenge_method"

To Reproduce

  1. Create a client called test in keycloak UI in a realm named test with:
  • Access type: public
  • Flow: Standard only
  • Valid redirect URIs: myapp://Homepage
  • Proof Key for Code Exchange Code Challenge Method: S256
  1. Have the following init options in ReactNativeKeycloakProvider
   <ReactNativeKeycloakProvider
      authClient={keycloak}
      initOptions={{
        redirectUri: 'myapp://Homepage',
        pkceMethod: 'S256',
        inAppBrowserOptions: {
        },
      }}
    >
      <Login />
    </ReactNativeKeycloakProvider>
  1. Run the app, click the login button, click continue after seeing "myapp wants to use localhost to sign in" popup
  2. See error

Expected behavior

React-native keycloak should pass in the parameter code_challenge_method.

Screenshots

Error screenshots:

image

Keycloak client settings screenshots (zoom in if can't see first image):

image
image

Code screenshots:

image
image

Smartphone

  • Device: iPhone 11
  • OS: 14.3
  • Version: not sure

unauthorized_client: Client secret not provided in request

I am using Google identity provider, by calling keycloak.login({idpHint: 'google'}) function, a new user gets created successfully on keycloak admin console, but I am unable to get its access token. The call for access token is being made internally by this package. Is there a way to provide clientSecret to the KeyCloak?

keycloak.login goes to invalid URL

Describe the bug

When using keycloak.login() it goes to an url with a query parameter &adapter=function+RNAdapter%28client%2C+_keycloakConfig%2C+initOptions%29+%7B%0A++++++%280%2C+_classCallCheck2.default%29%28this%2C+RNAdapter%29%3B%0A++++++this.client+%3D+client%3B%0A++++++this.initOptions+%3D+initOptions%3B%0A++++%7D, this results in a 502 Bad Gateway response.

To Reproduce

Expected behavior

Screenshots

Smartphone

  • Device:
  • OS:
  • Version

Additional context

Android resource linking failed

I am executing your example and when i build, I am facing an issue

"Execution failed for task ':app:processDebugResources'.
A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
Android resource linking failed
D:\Projects\app\mapp\node_modules\react-native-inappbrowser-reborn\android\build\intermediates\library_manifest\debug\AndroidManifest.xml:14:5-18:15: AAPT: error: unexpected element found in ."

When running example encounter Error: Unable to resolve module `@babel/runtime/helpers/interopRequireDefault`

Describe the bug
When trying to run the example. I get error:

error: Error: Unable to resolve module `@babel/runtime/helpers/interopRequireDefault` from `../src/index.ts`: @babel/runtime/helpers/interopRequireDefault could not be found within the project.

If you are sure the module exists, try these steps:
 1. Clear watchman watches: watchman watch-del-all
 2. Delete node_modules: rm -rf node_modules and run yarn install
 3. Reset Metro's cache: yarn start --reset-cache
 4. Remove the cache: rm -rf /tmp/metro-*

To Reproduce
cd example
yarn install
cd ios
pod install
yarn start
yarn run ios

Expected behavior
Runs the example

Smartphone
Android (emulator) + iPhone 11

  • Device: iPhone 11
  • OS: 15.2

Additional context
The example is probably outdated?

Getting Authenticated "false" and token "undfined" after login

on keycloak.login(), it's taking me to server's login web view. After logging in it's taking me back to App. The problem I am facing is that I am unable to get Token from keycloak using usekeycloak() hook.

const {keycloak} = useKeycloak();
console.log(keycloak.token);

Please help, I will be thankful to you.

Get a issue when I call keycloak.login().

When I run in emulator Pixel 5 API 30 (Androud 11 Google APIs), there is a error: "Error: InAppBrowser not available". (like below image), but when I use physical device (Android 11), there's no problem with InAppBrowser here, but after I login, keycloak?.authenticated still returns false. I wonder that there is any issue here or I forgot any step. I would appreciate any suggestions.
image

Here is some config file following instructions:

  1. android/app/src/main/AndroidManifrest.xml
    image
  2. android/build.gradle
    image
  3. android/app/src/main/.../MainApplication.java
    image
  4. android/setting.gradle
    image
  5. android/app/build.gradle
    image

JSON Parse Error

Describe the bug
After login successful from the browser, I'm getting [Error: SyntaxError: JSON Parse error: Unrecognized token '<']

Previously everything was working correctly, but it stopped working.

The error is not from keycloak side, because I'm able to login and then redirected to the mobile app. So probably some parsing error? It's trying to parse HTML page? I'm also able to use PostMan to get access_token using password as grant_type.

Package Versions :

  • @react-keycloak/native : ^0.5.1
  • react-native-inappbrowser-reborn : ^3.4.0
  • react-native : 0.62.2

Thanks for the repo ⚡

Clear Authenticated Session on Android

Describe the bug
In some cases, when the user wants to change accounts in social login, the library takes the data of the last authenticated account.
Is there a way to clear the session in authentication with social login?

Android: Authentication flow failed

Describe the bug
I have followed the instructions and the authentication flow seems to not working correctly on android (on ios works fine).

I'm getting the following error:

 WARN  EventEmitter.removeListener('url', ...): Method has been deprecated. Please instead use `remove()` on the subscription returned by `EventEmitter.addListener`.
 WARN  Possible Unhandled Promise Rejection (id: 0):
Error: Authentication flow failed
login$@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=gr.app&modulesOnly=false&runModule=true:108519:32
tryCatch@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=gr.app&modulesOnly=false&runModule=true:23399:23
invoke@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=gr.app&modulesOnly=false&runModule=true:23569:32
tryCatch@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=gr.app&modulesOnly=false&runModule=true:23399:23
invoke@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=gr.app&modulesOnly=false&runModule=true:23471:30
http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=gr.app&modulesOnly=false&runModule=true:23481:21
tryCallOne@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=gr.app&modulesOnly=false&runModule=true:28074:16
http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=gr.app&modulesOnly=false&runModule=true:28175:27
http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=gr.app&modulesOnly=false&runModule=true:28690:26
_callTimer@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=gr.app&modulesOnly=false&runModule=true:28586:17
_callImmediatesPass@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=gr.app&modulesOnly=false&runModule=true:28625:17
callImmediates@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=gr.app&modulesOnly=false&runModule=true:28835:33
__callImmediates@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=gr.app&modulesOnly=false&runModule=true:3052:35
http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=gr.app&modulesOnly=false&runModule=true:2830:34
__guard@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=gr.app&modulesOnly=false&runModule=true:3035:15
flushedQueue@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=gr.app&modulesOnly=false&runModule=true:2829:21
flushedQueue@[native code]
invokeCallbackAndReturnFlushedQueue@[native code]

To Reproduce
My configuration:

// Setup Keycloak instance as needed
// Pass initialization options as required
const keycloak = new RNKeycloak({
  url: 'https://sso.test.io/auth/',
  realm: 'test',
  clientId: 'test',
});

const initOptions = {
  redirectUri: 'app://Homepage',
  // if you need to customize "react-native-inappbrowser-reborn" View you can use the following attribute
  inAppBrowserOptions: {
    // For iOS check: https://github.com/proyecto26/react-native-inappbrowser#ios-options
    // For Android check: https://github.com/proyecto26/react-native-inappbrowser#android-options
  },
};

const App = () => (
  <ReactNativeKeycloakProvider authClient={keycloak} initOptions={initOptions}>
    <NativeRouter>
      <Route exact path="/" component={Home} />
      <Route path="/video" component={Video} />
    </NativeRouter>
  </ReactNativeKeycloakProvider>
);
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="gr.app">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />


    <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|screenSize|uiMode"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize">
        <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" />
            <data android:scheme="app" />
        </intent-filter>
      </activity>
    </application>
</manifest>

Expected behavior

  • No errors (in console) during the authentication flow.
  • Expecting to see the token (as in the example)

Smartphone

  • Device: Android emulator (Pixel 4)
  • OS: Mac
  • Version: 3.3.0 (RN 0.65.1)

Session should be clear once user reinstall the app

We save the session/cookies by using ephemeralWebSession: false then if user reinstalls the application again then session won't clear. But in most of the scenarios user should enter his/her credentials to login into the app.

So can we clear the session if the user reinstalls the application on his device?

ERROR: Possible Unhandled Promise Rejection (id: 2): Invariant Violation: InAppBrowser.openAuth is in a bad state. _redirectHandler is defined when it should not be.

Hi
I am getting below error after successful authentication, causing the hindrance in redirection to homepage:

Possible Unhandled Promise Rejection (id: 2):
Invariant Violation: InAppBrowser.openAuth is in a bad state. _redirectHandler is defined when it should not be.

Sometimes the above error is not there and authentication is successful but tokens are undefined.

Please help with this.
Thanks in advance.

@IronTony @panz3r

onTokens triggered but token list is undefined

Describe the bug
Hi Keycloak team, thank you very much for providing this library. I could login using keycloak account, so it worked. I only have an issue with empty token. My problem is as below:

I am implementing keycloak auth for react native app. And I am having problem with onTokens giving empty token list. Even thought onEvent was triggered with onAuthSuccess

Here is my keycloak client

import { RNKeycloak } from '@react-keycloak/native';
 
const keycloak = new RNKeycloak({
  url: 'https://MYDOMAIN/auth',
  realm: 'MYREALM',
  clientId: 'account',
});

export default keycloak;

Implemented keycloak provider in root top App as below

<ReactNativeKeycloakProvider
			authClient={keycloak}
			initOptions={{
				redirectUri: 'MYAPP://auth',
				inAppBrowserOptions: {},
			}}
			onEvent={(event, error) => {
				console.log('=======>keycloak onEvent', event, error);
			}}
			onTokens={(tokens) => {
				console.log('=========>keycloak onTokens', tokens);
			}}
		>

...

A login button which triggers keycloak.login as below:
...

const LoginWithKeycloak = ({ label, type, onSuccess, onError }) => {
  const { keycloak } = useKeycloak();

  const handleLogin = () => {
    keycloak?.login(
      {
        prompt: 'login',
      }).then(() => {
        if (onSuccess) onSuccess();
      })
      .catch((error) => {
        if (onError) onError(error);
      })
  };

...
upon onSuccess it will navigate to next screen

To Reproduce

  1. Trigger keycloak.login
  2. Login successfully in InAppWebview keycloak login page
  3. Observe onEvent and onTokens
  4. onEvent was onAuthSuccess and no error
  5. onToken was called but all tokens were undefined

Expected behavior
onTokens to return valid tokens instead of undefined

Screenshots
Log of events could be captured as below
image

Smartphone

  • Device: iphone
  • OS: 14.5
  • Version: 0.5.5

Keycloak:React-native:Android: Object.fromEntries is not a function

Getting error while authenticating using keycloak:
[TypeError: Object.fromEntries is not a function. (In 'Object.fromEntries(oAuthParams.entries())', 'Object.fromEntries' is undefined)]

Solution Tried:
I tired to use a plugin to fix this issue:
https://www.npmjs.com/package/babel-plugin-transform-object-from-entries , but issue was still not resolved.

I guess the issue here is that: object.fromentries is not supported by many js engine. May be we need a alternative for this or any other solution.

Versions used:
node: v12.18.3
react: ~16.9.0
@react-keycloak/native: "^0.5.1"
react-native-inappbrowser-reborn: "^3.5.1"
react-native: "^0.63.3"

Please provide help here. Thanks in advance.
@IronTony @panz3r

Navigation error after authetication

Describe the bug

Hi
After successful authentication, I am receiving the error that follows in the print below.

Thank you for your help.

Screenshots

Screen Shot 2021-01-07 at 15 20 57

To Reproduce

My Navigator component:

const AuthStack: React.FC = () => {
 const { Navigator, Screen } = createStackNavigator();
 return (
   <Navigator>
     <Screen name="signinkeycloak" component={SignInKeycloak} />
   </Navigator>
 );
};

My Keycloack configuration:

<ReactNativeKeycloakProvider
      LoadingComponent={<Text>Loading</Text>}
      authClient={keycloak}
      initOptions={{
        redirectUri: 'myapp://signinkeycloak',
        inAppBrowserOptions: {
          modalPresentationStyle: 'fullScreen',
          enableBarCollapsing: false,
          modalEnabled: true,
          ephemeralWebSession: true,
          dismissButtonStyle: 'ok',
        },
      }}>
      <NavigationContainer linking={linking}>
        <ContextProvider>
          <StatusBar barStyle="dark-content" backgroundColor="#FFF" />
          <Routes />
        </ContextProvider>
      </NavigationContainer>
    </ReactNativeKeycloakProvider>

Complete Example

Hi,
Thank u for your work. The example in example directory seems incomplete.
Can you provide a simple "complete" example please?

Thanks in advance.

Problem in the Build APK

Thank you for the excellent repo and excellent documentation.

I have configured everything and in the debug APK everything works fine, but when I create a build APK and try to test it, authentication fails after the redirect to app.

What works:

  • Browser is opening
  • Credentials are verified and redirected to app

What doesn't works:

  • After redirect(in build version only) AuthError is thrown.

I tried to print the error msg in the build version, I'm getting following :
{"line" : "992" , "column" : 11311, "sourceURL" : "index.android.bundle"}

I tried recreating the bundle and also managing assets. But I'm getting same problem.

Handle promise rejection when passing redirectUri to logout method

Describe the bug
When passing a redirectUri to the logout method, there is a promise rejection with the error: Logout flow failed

To Reproduce

  1. Pass a redirectUri to the logout method.
    await keycloak?.logout({ redirectUri: ${KEYCLOAK_REDIRECT_URI}onBoarding, })
  2. Do the logout
  3. Profit

Expected behavior
When logging out have the event handled by the provider and not an unhandled promise.

Screenshots
image

Smartphone
ALL

How to using implicit flow keycloak with react native?

I need to get access_token from keycloak.
Currently, I am getting grant_type = client_credentials and client_id, client_secret;
But due to some system requirements we need to use implicit flow. But I can't get the password so I can't get the token with grant_type = password.
I use react native and am using curl to get tokens. Is there any solution that can help me? Please?

Redirect uri is not working

Describe the bug

To Reproduce

Expected behavior

Screenshots

Smartphone

  • Device:
  • OS:
  • Version

Additional context

What should I put in Valid redirect uris in console of Keycloak when auhentication is succefull

Hi, I'm new with autentication in keycloak.

Right now I can open the browser to enter the credentials, but when tap on Log in
image

this page send me to inside of console of keycloak, but I need close the browser and return me to my app.

Maybe some one can explain me how can I do that.

Because I know I can modify the field valid redirect uris inside of console of keycloak, but I don't sure what path I should put there for return me to my app.

A generic exception is being thrown when the user closes the InAppBrowser

This is the code now in the adapter.tsfile:

const res = await InAppBrowser.openAuth(
  loginUrl,
  this.client.redirectUri!,
  this.initOptions.inAppBrowserOptions
);

if (res.type === 'success' && res.url) {
  const oauth = this.client.parseCallback(res.url);
  return this.client.processCallback(oauth);
}

throw new Error('Authentication flow failed');

I believe the module should throw a specific exception when the user closes the InAppBrowser:

const res = await InAppBrowser.openAuth(
  loginUrl,
  this.client.redirectUri!,
  this.initOptions.inAppBrowserOptions
);

if (res.type === 'success' && res.url) {
  const oauth = this.client.parseCallback(res.url);
  return this.client.processCallback(oauth);
}

+if (res.type === 'close') {
+  throw new Error('User has closed the browser')
+}

throw new Error('Authentication flow failed');

keycloak.onTokenExpired callback is not invoking

onTokenExpired callback is not invoking properly very first time once the token got expired. However, it's working fine for next time. For example:- if the token expired time is 5 minutes then it will invoke in 10 minutes(2x times) first time, after that it would be invoked in every 5 minutes.

keycloak.onTokenExpired = () => { keycloak?.updateToken(240).then((refreshed) => { if (refreshed && keycloak.token) { Alert.alert('Token was successfully refreshed12'); } else { Alert.alert('Token is still valid'); }}).catch(() => { Alert. alert('Failed to refresh the token, or the session has expired); }); };

It should invoke every 5 minutes if the token expired time is 5 minutes.

  • Device: iPhone 12
  • OS: IOS
  • Version 15.2.1

Thank You

Auto login issue

I have an issue about chrome process. Looks like if I terminate Chrome, it will terminate all process include browser in app.

Reproduce:

  1. Login.
  2. Terminate app
  3. Open chrome
  4. Terminate chrome
  5. Open app will not auto login

Expected behavior:
Keep process in app and auto login.

Smartphone
All android.
iOS not tested.

redirect setting for android

i already added scheme myapp name on mainfest. but still not work after authorize, response still not reponse to app, can you make it example configure

iOS 14.5 invalid redirect schema

Describe the bug

Trying to log in using a iOS 14.5 device throws the following exception and crashes the app.

My options look like:

    initOptions={{
        redirectUri: 'myapp://home',
        inAppBrowserOptions: {
          modalPresentationStyle: 'fullScreen',
          enableBarCollapsing: false,
          modalEnabled: true,
          ephemeralWebSession: true,
          dismissButtonStyle: 'ok',
        },
      }}

Everything works fine on iOS 14.4 or below.

To Reproduce

  1. Boot a new RN app
  2. have a button with an onPress event triggering await keycloak?.login();
  3. Error appears on the red screen

Expected behaviour

To be able to open the browser with no error.

Screenshots

image

Smartphone

  • Device: any
  • OS: iOS
  • Version: strictly on 14.5

Additional context

Logs me in but then I get Network request failed error

Hi there!

I have integrated this library in my client and it was working fine, then I had to change endpoints to point to the new server we have on google cloud and something seems to have broken, it looks like I do get logged in, I can see it from keycloak console, but instead of getting the event onAuthSuccess I get onAuthError and of course I don't get the tokens. Unfortunately the error message doesn't say much 'Network request failed' and I can't understand what's going on.

This happens after calling Keycloak.login(), the webview opens up, I put in my credentials, everything seems to work just fine, but when the webview closes and I get back to the app I get the above error event.

I'm testing on a Pixel 3a with Android version 10

Any help would be very appreciated!

does not access emulator

Hello Friend.

thanks for the library.
I was a little confused ... because I am implementing and via the browser the link localhost: 8080 / auth of the keycloak I can access ...

however if I try to do this through my emulator of the android app .. it does not access the page .. what is the problem?

see in the image.
image

my keycloak.js is
`
import { RNKeycloak } from '@react-keycloak/native';

// Setup Keycloak instance as needed
// Pass initialization options as required
const keycloak = new RNKeycloak({
realm: "XXXXX",
url: "http://localhost:8080/auth",
clientId: 'ui',
});

export default keycloak;`

TypeError: Network request failed

good night,

I know that is not the focus .. but I have this problem when I make 1 request after login ...

what could be going wrong?

thank you

image

`const lista = () => {

const [isLoading, setLoading] = useState(true);
const [data, setData] = useState([]);

useEffect(() => {
  fetch('GET', 'http://192.168.0.102:8082/agendas/ativas', {
    'Content-Type': 'application/json',
  })
    .then((response) => response.json())
    .then((json) => setData(json.agendas))
    .catch((error) => console.error(error))
    .finally(() => setLoading(false));
}, []);

return (
  <View style={{ flex: 1, padding: 24 }}>
    {isLoading ? <ActivityIndicator/> : (
      <FlatList
        data={data}
        keyExtractor={({ id }, index) => id}
        renderItem={({ item }) => (
          <Text>{item.nome}, {item.cor}</Text>
        )}
      />
    )}
  </View>
);

};
export default lista`

Handle promise rejection when come back from in-app browser

Describe the bug
Can't handle the promise rejection when pressing the back/close icon of the in-app browser.

To Reproduce

  1. Implement the lib
  2. When the in-app browser shows up, click the black/close icon
  3. In your terminal you'll have an error like this:
Possible Unhandled Promise Rejection (id: 0):
Error: Authentication flow failed

Expected behavior
I would like to have a method to handle the rejections of this Promise.

Screenshots
image

Smartphone
ALL

Additional context
Can't handle the error via the onEvent callback as it wraps only the event from Keycloak.

How to add client secret in settings?

Hello everyone, I have a server with Access Type confidential and I need to send the secret key to authenticate correctly. I didn't find in the documentation how to send this field correctly. Can someone help me?

Thanks in advance.

how can i recover keycloak instance created useKeycloak hooks?

Hi! First of all, I really appreciate your service.
I have a question about maintaining login after app restart.

This is my senario.

  • Login in my app at first, issued an access token & refresh token with keycloak.login().
  • Store an access token & refresh token to local storage with onToken event handler.
  • Use the useKeycloak hooks for getting access token and using keycloak.authenticated, keycloak.tokenparsed, etc.
  • After restarting my app, load an access token & refresh token from local storage

In this senario, when I get keycloak instance from a useKeycloak hooks after restarting my app, there is no access token & refresh token in keycloak instance.
I want to use a keycloak instance just like when I first login(not only use stored access token & refresh token).
Is there the way initialize keycloak instance including stored access token & refresh token after restarting my app without login?
Thank you.

React Native Warning on setTimeout

Describe the bug
Recieving a warning after authenticating.

WARN: Setting a timer for a long period of time, i.e. multiple minutes, is a performance and correctness issue on Android as it keeps the timer module awake, and timers can only be called when the app is in the foreground. See facebook/react-native#12981 for more info.
(Saw setTimeout with duration 299418.9999103546ms)

To Reproduce

  1. Set up authentication.
    1a. Use default client settings for keycloak.
  2. Use useKeycloak.
  3. Use login function provided by useKeycloak.
  4. Login, and successfully authenticate.
  5. A warning to your debugger/console will then appear.

Expected behavior
No warning to appear, or use a different method of requesting for a token refresh.

Smartphone

  • Device: Samsung S8
  • OS: Android 9
  • Version v0.5.1

Additional context
https://github.com/react-keycloak/keycloak-ts/blob/42637a6fe47e3714a4ebbd6abefb2c2fd63f19c0/src/client.ts#L887-L890

Doesn't keep login status on relaunch

Describe the bug
Firstly really appreciate the lib but I've noticed, once the user kills the app after logging in, next time they open the app it doesn't recognize the user is logged in.

Is there something I'm missing?

how I can customize the URL will send

At the moment I have:

keycloak.js

import { RNKeycloak } from '@react-keycloak/native'

// Setup Keycloak instance as needed
// Pass initialization options as required
const keycloak = new RNKeycloak({
  url: 'https://MY_URL/auth/',
  realms: 'MY_REALM',
  realm: 'MY_REALM',
  clientId: 'MY_CLIENTID',
  account: 'MY_CLIENTID',
  // if you need to customize "react-native-inappbrowser-reborn" View you can use the following attribute
  inAppBrowserOptions: {
    // For iOS check: https://github.com/proyecto26/react-native-inappbrowser#ios-options
    // For Android check: https://github.com/proyecto26/react-native-inappbrowser#android-options
  }
})

export default keycloak

app.js


import keycloak from './keycloak'

function App () {
  return (
    <ReactNativeKeycloakProvider
      authClient={keycloak}
      initOptions={{ redirectUri: 'https://MY_URL/auth/realms/MY_REALM/MY_CLIENTID/login-redirect'}}
    >
      <Provider store={store}>
        <Routes />
      </Provider>
    </ReactNativeKeycloakProvider>
  )
}

With this current code, when I try to execute the method:

keycloak?.login()

the app show me the alert:

image

Until this step, everything is great, but when will to open the browser use a URL wrong.

URL WORNG: https://MY_URL/auth/realms/MY_REALM/protocol/openid-connect/auth?client_id=MY_CLIENTID&redirect_uri=https%3A%2F%2FMY_URL%2Fauth%2Frealms%2FMY_REALM%2Faccount%2Flogin-redirect&**state=e3c614f2-53de-4fdf-886e-52223915bac6&response_mode=fragment**&response_type=code&scope=openid
until attribute redirect_uri is ok, but when start the attribute state all change.

Where I need to send mi is:

URL I NEED: https://MY_URL/auth/realms/MY_REALM/protocol/openid-connect/auth?client_id=MY_CLIENTID&redirect_uri=https%3A%2F%2FMY_URL%2Fauth%2Frealms%2FMY_REALM%2Faccount%2Flogin-redirect&state=0%2F79fbc5e0-c70d-4eef-bf5d-ed6c9b6b555e&response_type=code&scope=openid

so, any idea how I can customize the attribute state and remove response_mode from wrong url?

[iOS] Safari doesn't keep cookies

Describe the bug
When logging on iOS, and then killing the app, the next time you open it, it asks you to login again.
On Android, chrome keeps the cookies.

I'm using the login-required option of keycloak.

Thore are the initOptions

initOptions={{
    redirectUri: ${KEYCLOAK_REDIRECT_URI}home,
    responseMode: 'query',
    onLoad: 'login-required',
    inAppBrowserOptions: {
      // For iOS check: https://github.com/proyecto26/react-native-inappbrowser#ios-options
      // For Android check: https://github.com/proyecto26/react-native-inappbrowser#android-options
      // Android Properties
      showTitle: false,
      toolbarColor: '#006199',
      secondaryToolbarColor: 'black',
      enableUrlBarHiding: true,
      enableDefaultShare: false,
      forceCloseOnRedirection: true,
      hasBackButton: true,
      showInRecents: false,
    },
}}

To Reproduce

  1. Create an app
  2. Use the provider
  3. Do the login
  4. Kill the app
  5. Open it again
  6. It asks you to login again

Expected behavior
If the session is valid, do the login automatically as on Android.

Smartphone
All iOS Devices

Additional context
I think is an issue with the inAppBrowser, if so, any workaround?
If I have to use the check-sso option, how to handle the cookies with the silent option?
How to "link" the html file with the iframe?

Deep linking issue on Android

I believe I am running into an issue with linking on Android. It seems to be the #state=... portion that is throwing react-navigation off from picking up the link. Testing deeping linking works via CLI: npx uri-scheme open io.act.auth://CreateCheckin --android.

Heres is my linking config:

prefixes: ["io.act.auth://"],
config: {
  screens: {
   CreateCheckin: {
     path: "CreateCheckin"
    }
  }
}

Here is the redirect URI that react-navigation is trying to parse:

io.act.auth://CreateCheckin#state=978f7de7-42a1-424d-bacd-53a746c030ab&session_state=0436a428-d734-490f-a3bc-812712458efd&code=6627fcff-abac-4139-99b7-54ed2d2a9fee.0436a428-d734-490f-a3bc-812712458efd.011ac3f2-b54f-419d-8108-6b1b67bd3f12

What would be the proper config to match the #state... portion?

Originally posted by @joe307bad in #27 (comment)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.