react-native-keycloak icon indicating copy to clipboard operation
react-native-keycloak copied to clipboard

Error: fetchTokens failed

Open Ma3aXaH opened this issue 3 years ago • 2 comments
trafficstars

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

  • Device: Android Emulator
  • OS: Android 11

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>

Ma3aXaH avatar Sep 27 '22 09:09 Ma3aXaH

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

zvitek avatar Oct 17 '22 08:10 zvitek

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

zvitek avatar Oct 17 '22 09:10 zvitek

@Ma3aXaH did you find a solution?

wolfzer44 avatar Mar 29 '23 00:03 wolfzer44