-
Notifications
You must be signed in to change notification settings - Fork 268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to initialize keycloak with locale in i18n Angular app? #72
Comments
@kashpatel, one option could be initialize the KeycloakService but not redirect to the login page when calling the init method. This is similar to the keycloak-events example. Just a note, the example is not finished but you can take a look on how the app is dealing with the login workflow. Then you have two options, depending on your use case:
After login the keycloak will redirect to the origin url (/en, /fr, .. ). If this suggestion doesn't not helps you, please let me know then we may think for another options. |
Hey @mauriciovigolo, Thank you for getting back to me and sorry for late reply. I tried doing exactly you told but now I got the following error. https://localhost/auth/realms/realm/account 401 (Unauthorized) So, I followed your previous comment from this issue: #37 and added 'view-profile' role in to myapp's account but still no luck. Here is the snapshot of code I am using: keycloak.keycloakEvents$.subscribe(event => {
if (!keycloak.isLoggedIn) {
keycloak.getKeycloakInstance().login({ locale: 'fr' });
}
});
await keycloak.init({
config: keyCloakConfig,
initOptions: {
onLoad: 'check-sso',
checkLoginIframe: false
} }); Thanks a lot for this amazing library and have a great weekend. |
Hi @kashpatel, do you have an example to share, so I think it would be easier to help you. |
Hi @mauriciovigolo, I will get on it as soon as I get time. Have been busy lately. Thanks |
Hey @mauriciovigolo, Here is how I accomplished redirecting to login page based on site's @LOCALE_ID.
None of this would work if you use 'login-required' because keycloak-js does the internal redirect.
Hope that helps someone! |
Thanks @kashpatel, nice work! To help others I will also create a new example with this scenario. |
Hi,
Thanks. |
##Question or Feature Request
I know this might not be the best place for this question but just wondering if someone has encountered this problem? Since I could not find any solution online.
We use keycloak [https://www.keycloak.org/] server for user authentication in our Angular 6 app. We also use this wrapper library https://github.com/mauriciovigolo/keycloak-angular to interact with the underneath JavaScript keycloak Adapter and initialization.
Keycloak is the first thing in the app that gets initialized (from provided configuration) via Angular's APP_INITIALIZER provider.
Since we use Angular with internationalization and ahead of time compilation, we have deployed our apps like this:
https://my-site/en
https://my-site/fr
I want to render login page in respective locale when navigated. If navigated to my-site/fr keycloak login page should render in french and so on. But there is no way to provide locale in keyclaok config while app initialization.
PS: Keycloak realm is already configured to allow internationalization and user can change language from login page. I know keycloak adapter's login method takes "locale" param but I can only access that after app has been initialized.
Has anyone encountered this problem?
Thank you
The text was updated successfully, but these errors were encountered: