Required String parameter 'client_id' is not present Error during logout
only1chi opened this issue · comments
Issue
I am trying to signout a user with the logout function. I am using Amazon cognito which is our IDP.
It is enabled for I enabled 'Sing Out Idp Flow' as suggested by AWS documentation.
I successfully login with auth configuration as follows:
const config = {
clientId: <our client id>,
redirectUrl: "myapp://myclient/redirect",
serviceConfiguration: {
authorizationEndpoint: `${domainName}/oauth2/authorize`,
tokenEndpoint: `${domainName}/oauth2/token`,
revocationEndpoint: `${domainName}/oauth2/revoke`,
endSessionEndpoint: `${domainName}/logout`
},
additionalParameters: {
identity_provider: <our identity provider>,
client_id: <our client id>
}
};
When we want to logout, we call the logout endpoint as follows:
const response = await logout(config, {
idToken: currentIdToken,
postLogoutRedirectUrl: config.redirectUrl
}).catch(e => {
const { code, message, userInfo } = e;
console.log("logout error: ", { message, code, userInfo });
});
The logout works partially in the sense that it successfully logs out the user from the IDP. However, it seems to get stuck somewhere between the logout and the redirect.
We get a message saying:
Required String parameter 'client_id' is not present
And the app is stuck on that a screen.
We have provided client_id
as an additional parameter. I don't understand why it is not supplied to the logout endpoint.
Any ideas on how to resolve this?
Environment
- Your Identity Provider:
e.g. IdentityServer Azure (using AWS Cognito)
- Platform that you're experiencing the issue on:
both
- Your
react-native
Version:0.71.11
- Your
react-native-app-auth
Version:7.1.0
- Are you using Expo?
No
Did you fix this? I have same problem.
@tvojtech I did find a way to work around this issue. We do provide the client_id
, which allows us to successfully logout. However, Cognito will report an error about logout_uri
and redirect_uri
which is not provided and is not useful for our application. So we catch that error and move on. The important fact is that we successfully sent the logout request to the IDP and the user is successfully logged out.
Here is what our logout function looks like:
const logoutCurrentUser = useCallback(async () => {
const idToken = getCurrentUsedIdToken();
if (idToken != null) {
const clientId = getClientIdMetadata(idToken);
const identityProvider = getIdentityProviderMetadata(idToken);
const currentConfig = getAuthConfig(clientId, identityProvider);
const config = {
...currentConfig,
iosPrefersEphemeralSession: true,
additionalParameters: {
...currentConfig.additionalParameters,
client_id: clientId,
response_type: "code",
redirect_uri: `${currentConfig.redirectUrl}`
}
};
if (clientId != null && identityProvider != null) {
const response = await logout(config, {
idToken,
postLogoutRedirectUrl: config.redirectUrl
}).catch(e => {
// Have to catch this error because cognito does not fully handle
// logout_uri and redirect_uri
const { code, message, userInfo } = e;
logger.log("caught logout error: ", { message, code, userInfo });
});
return response;
}
}
return null;
}, [getAuthConfig, getClientIdMetadata, getIdentityProviderMetadata, logger]);