react-keycloak / react-native-keycloak

React Native components for Keycloak
MIT License
171 stars 48 forks source link

Error: fetchTokens failed #108

Closed Ma3aXaH closed 2 years ago

Ma3aXaH commented 2 years ago

Description Library constantly throws "Error: fetchTokens failed" after authorization. The authorization itself is successful. If done from a browser, login and password are valid and it opens the application, but when done from the app it closes in-app-browser and throws the aforementioned error. The keycloak server is setup properly, other web projects use it successfully, problem only occurs in react native implementation.

onEvent triggers with the following message: onKeycloakEvent onAuthError {"error": [Error: fetchTokens failed], "error_description": "Failed to refresh token during callback processing"}

To Reproduce Steps: 1) Start application 2) Press Login 3) Enter email and password 4) Press Sign In

Expected behavior After authorization keycloak updates state to authenticated.

Smartphone

Additional context Here's the app code (same as the example, but with different app uri scheme and different keycloak url, realm, clientId):

const Login = () => {
  const {keycloak} = useKeycloak();

  return (
    <View style={styles.container}>
      <Text>{`Welcome ${keycloak?.authenticated} - ${keycloak?.token}!`}</Text>
      <Button onPress={() => keycloak?.login()} title="Login" />
    </View>
  )
}

const App = () => {
  return (
    <ReactNativeKeycloakProvider
      authClient={keycloak}
      initOptions={{ redirectUri: 'posbpay://Homepage' }}
      onEvent={(event, error) => {
        console.log('onKeycloakEvent', event, error);
      }}
    >
      <Login />
    </ReactNativeKeycloakProvider>
  );
}

Intent filter configuration in AndroidManifest:

        <intent-filter>
            <data android:scheme="posbpay" />
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
        </intent-filter>
zvitek commented 2 years ago

Hello, I have the same error on iOS. Have you figured out where the problem is?

zvitek commented 2 years ago

We found a solution to the problem. You have to set the Access Type parameter to public in the client settings and everything will work.

image
wolfzer44 commented 1 year ago

@Ma3aXaH did you find a solution?