alexziskind1 / nativescript-oauth2

Other
85 stars 93 forks source link

CustomProvider - Keycloak - ERROR: JS: back to main page with error - JS: incomplete #218

Open rosinedesmet opened 1 year ago

rosinedesmet commented 1 year ago

Make sure to check the demo app(s) for sample usage: done

Make sure to check the existing issues in this repository: done

If the demo apps cannot help and there is no issue for your problem, tell us about it

Please, ensure your title is less than 63 characters long and starts with a capital letter.

Which platform(s) does your issue occur on?

Please, provide the following version numbers that your issue occurs with:

Please, tell us how to recreate the issue in as much detail as possible.

Describe the steps to reproduce it.

When clicking on the login button, my authentification is not loaded and I have the following error. It seems like my authentification does not have the time to load !

  JS: WebView loadStarted http://xx.xxx.xxx.xxx:8080/realms/x/protocol/openid-connect/auth?...response_mode=query&state=abcd
  JS: back to main page with error:
  JS: incomplete
  JS: Error: incomplete
  JS: WebView loadFinished http://xx.xxx.xxx.xxx:8080/realms/x/protocol/openid-connect/auth?client_id=...scope=openid&response_mode=query&state=abcd

(When typing the url in Chrome without going through nativescript I do not have any problem)

Is there any code involved?

  1. Implement the demo angular code (code)

  2. Define a configureOAuthProviderMyCustomProvider as below in the auth-providers-helper.ts file

    export function configureOAuthProviderMyCustomProvider(): TnsOaProvider {
    const keycloakProviderOptions: KeycloakProviderOptions = {
      openIdSupport: "oid-none",
      clientId: "xx",
      redirectUri: "http://xx.xxx.xxx.xxx:8080/",
      keycloakBaseUrl: 'http://xx.xxx.xxx.xxx:8080', 
      clientSecret: "x",
      realm: 'xx',
      scopes: ["openid"],
    };
    const keycloakProvider = new KeycloakProvider(
    keycloakProviderOptions
    );
    return keycloakProvider;
    }
  3. Define KeycloakProviderOptions and KeycloakProvider as in this issue

export interface KeycloakProviderOptions extends TnsOaUnsafeProviderOptions {
    realm: string;
    keycloakBaseUrl: string;
}

export class KeycloakProvider implements TnsOaProvider {
    authority: string;
    authorizeEndpoint: string;
    cookieDomains: string[];
    providerType: TnsOaProviderType;
    tokenEndpoint: string;
    tokenEndpointBase: string;

    openIdSupport: string;

    constructor(public options: KeycloakProviderOptions) {
        const realm = options.realm;

        this.openIdSupport = "oid-none";
        this.providerType = "keycloak";
        this.authority = options.keycloakBaseUrl;
        this.tokenEndpointBase = options.keycloakBaseUrl;
        this.authorizeEndpoint = '/realms/'+realm+'/protocol/openid-connect/auth';
        this.tokenEndpoint = '/realms/'+realm+'/protocol/openid-connect/token';
        this.cookieDomains = [realm];
    }

    parseTokenResult(jsonData): ITnsOAuthTokenResult {
        return jsonData;
    }
}
  1. Click on the button login (cf. demo-angular). The GIF is below

keycloak-error

Thank you in advance for your responses ! 🙏