How can i redirect the user to registration link
Keycloak has register function to redirect the user to registration page.
keycloak.register({ redirectUri: redirectURI, }); How can i acheive same thing with our library. Thanks in advance
From what I've checked, the UserManager, which react-oidc-context internally uses, does not provide a signupRedirect.
If I am missing something I am all ears! You can always build the url manually of course.
What about
const auth = useAuth(); auth.signinRedirect();
Gets you to provider login page.
What about
const auth = useAuth(); auth.signinRedirect();Gets you to provider login page.
signInReqirect() function will return you to Login Page. I want to show the registration page instead of Login Page to the user. Thank you
The issue arises as keycloak uses a non-default OIDC method for this. Looking at their JS adapter implementation (https://github.com/keycloak/keycloak/blob/e69031d411c981fa78b8320b9588771069b4b86d/js/libs/keycloak-js/src/keycloak.js#L846), they have coded a registration endpoint, which will throw an error on access when a default OIDC configuration is used.
register: function() {
return getRealmUrl() + '/protocol/openid-connect/registrations';
},
So looking farther, what is done is the normal createLoginURL (which is done in this library with the createSigninRequest(args) in the UserManager.ts) is wrapped and the options passed have the attribute "action" set to "register". (https://github.com/keycloak/keycloak/blob/e69031d411c981fa78b8320b9588771069b4b86d/js/libs/keycloak-js/src/keycloak.js#L505)
This then causes that method to use the register endpoint instead of the authorize endpoint
if (options && options.action == 'register') {
baseUrl = kc.endpoints.register();
} else {
baseUrl = kc.endpoints.authorize();
}
and deactivates the '&kc_action=' URL parameter, while "building" the final URL :
var url = baseUrl
+ '?client_id=' + encodeURIComponent(kc.clientId)
+ '&redirect_uri=' + encodeURIComponent(redirectUri)
+ '&state=' + encodeURIComponent(state)
+ '&response_mode=' + encodeURIComponent(kc.responseMode)
+ '&response_type=' + encodeURIComponent(kc.responseType)
+ '&scope=' + encodeURIComponent(scope);
if (useNonce) {
url = url + '&nonce=' + encodeURIComponent(nonce);
}
.....
So, essentially, this is IMO not in the scope of this library. However, if someone would want to support this feature, this is probably the things that need to be done:
- Add 'register' endpoint to MetadataService
- Either
- Make the OidcClient.createSigninRequest aware of an alternative mode and add logic to use the register endpoint (instead of
const url = await this.metadataService.getAuthorizationEndpoint();) - or create a new Method for handling registrations.
- Make the OidcClient.createSigninRequest aware of an alternative mode and add logic to use the register endpoint (instead of
- Extend the UserManager with a method to handle passing appropriate register flags AND/OR controlling that via custom field in CreateSigninRequestArgs.
This is just a first idea, but very likely out of scope for this library. Maybe there are better ways of implementing this. If I magically find time, I might try something.
No news on this feature ?