react-native-keycloak
react-native-keycloak copied to clipboard
Error: fetchTokens failed
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:
- Start application
- Press Login
- Enter email and password
- 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>
Hello, I have the same error on iOS. Have you figured out where the problem is?
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.
@Ma3aXaH did you find a solution?