Giter Club home page Giter Club logo

Comments (4)

mauriciovigolo avatar mauriciovigolo commented on July 29, 2024 3

Hello @CodeBenson,

Sure we can help! So this is probably related to the initOptions you passed in the keycloak initialization. If you followed the examples in the README.md, the initOptions.onLoad has a value === 'login-required'. This value in the keycloak-js library, redirects the user to the login page.

Look at the example below:

 await keycloak.init({
    config: {
      url: 'http://localhost:8080/auth',
      realm: 'your-realm',
      clientId: 'client-id'
    },
    initOptions: {
      onLoad: 'login-required', // redirects to the login page
      checkLoginIframe: false
    },
    bearerExcludedUrls: [
      '/assets',
      '/clients/public'
    ],
  });
  resolve();
} catch (error) {}

In your case, the problem is related to this configuration or with the auth guard.

From the keycloak javascript adapter documentation:

By default to authenticate you need to call the login function. However, there are two options available to make the adapter automatically authenticate. You can pass login-required or check-sso to the init function. login-required will authenticate the client if the user is logged-in to Keycloak or display the login page if not. check-sso will only authenticate the client if the user is already logged-in, if the user is not logged-in the browser will be redirected back to the application and remain unauthenticated.

Try to change this value and also take a look at your routes, if the landing page has an auth guard configured. If it has an auth guard (the landing page), try to remove it.

Thanks!

from keycloak-angular.

m461c-b3n avatar m461c-b3n commented on July 29, 2024 2

Yeah sure, sorry should have told you. It worked with setting 'login-required' to 'check-sso'. Thanks again! 👍

from keycloak-angular.

mauriciovigolo avatar mauriciovigolo commented on July 29, 2024

@CodeBenson,

Will close this issue, since it seems to be ok. If you have any other doubts you can also use our slack at: keycloak-angular.slack.com .

See you there!

from keycloak-angular.

SandyKnock avatar SandyKnock commented on July 29, 2024

Is it possible to use a string in this form?

const str = JSON.stringify(        {
          "realm": "test",
          "auth-server-url": "http://localhost:8080/auth",
          "ssl-required": "external",
          "resource": "test",
          "public-client": true,
          "confidential-port": 0
        });

await keycloak.init({
    config: str ,
    initOptions: {
      onLoad: 'login-required', // redirects to the login page
      checkLoginIframe: false
    },
    bearerExcludedUrls: [
      '/assets',
      '/clients/public'
    ],
  });
  resolve();
} catch (error) {}

I get an error "GET http://localhost:4200/%7B%22realm%22:%22test%22,%22auth-server-url%22:%22http://localhost:8080/auth%22,%22ssl-required%22:%22external%22,%22resource%22:%22test%22,%22public-client%22:true,%22confidential-port%22:0%7D 404 (Not Found)" and "ERROR An error happened during Keycloak initialization."

kind of like config allows : "config?: string | KeycloakConfig;"

from keycloak-angular.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.