Skip to content
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 pass external login (from native app) JWT to keycloak-angular in webview? #511

Open
at2software opened this issue Aug 22, 2023 · 1 comment

Comments

@at2software
Copy link

Hi. We're currently struggling with passing a valid JWT token that we obtained from keycloak through a native login mask (iOS and Android) to a WebView Container with the angular application. Is there any way how we can open the angular application and pass the JWT to the keycloak module, so it will use it for further communication?

@at2software
Copy link
Author

I might have figured it out. Change the provider in app.module.ts as follows:

useFactory: (keycloak: KeycloakService, locationStrategy: LocationStrategy) => {
        return () => {
            let options: KeycloakOptions = {
                config: KeycloakProviderConfig,
                initOptions: {
                    onLoad: 'check-sso',
                    silentCheckSsoRedirectUri: `${window.location.origin}${locationStrategy.prepareExternalUrl('/assets/silent-check-sso.html')}`
                },
                loadUserProfileAtStartUp: true,
            }
            let params = new URLSearchParams(window.location.search)
            if (params.get('access_token') && params.get('refresh_token')) {
                options.initOptions!.adapter      = 'cordova-native'
                options.initOptions!.token        = params.get('access_token')!
                options.initOptions!.refreshToken = params.get('refresh_token')!
            }
            return keycloak.init(options)
        }
    }

then you can pass access_token and refresh_token as GET params to any angular URL and keycloak-angular seems to accept it. No idea, if token refresh will work with it as well, but for now it seems to do the trick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant