JohannesBauer97 / keycloak-ionic-example

Connecting Ionic (Capacitor) with Keycloak
10 stars 1 forks source link

Open keycloak login page in embedded browser #2

Open GLY-JeffreyTCK opened 1 year ago

GLY-JeffreyTCK commented 1 year ago

Hi, this article is awesome but can this open in embedded browser ?

JohannesBauer97 commented 1 year ago

I haven't done it yet, but I'd start with the openUri config:

/**
 * This property allows you to override the method that is used to open the login url,
 * allowing a way for implementations to specify their own method of routing to new
 * urls.
 */
public openUri?: (uri: string) => void = (uri) => {
  location.href = uri;
};

Override this to use the embedded browser plugin of your choice. When the user completes login and Keycloak redirects back, it might work automatically, or you need to manually listen for the redirect back parameters and provide them to the oauth2 library.

GLY-JeffreyTCK commented 1 year ago

@JohannesBauer97 yeah i just tried out with openUri config and it works with Code + PKCE flow with your code in login function but the redirect back after logged in always got "Validating access_token failed, wrong state/nonce" issue so hasValidAccessToken always false then have to reinit login function only able to retrieve access token

hmoazzem commented 1 year ago

@JohannesBauer97 @GLY-JeffreyTCK have you managed to solve this? I've a kinda working demo at https://github.com/edgeflare/keycloak-angular-capacitor, but it's certainly not fit for production.