GithubHelp home page GithubHelp logo

witcom-gmbh / keycloak-authz-angular Goto Github PK

View Code? Open in Web Editor NEW
5.0 5.0 8.0 1.67 MB

Setup Keycloak Authorization for Angular applications

License: GNU General Public License v3.0

JavaScript 4.47% TypeScript 95.53%

keycloak-authz-angular's People

Contributors

iceman91176 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

keycloak-authz-angular's Issues

Angular 14

Hey everyone!

I would like to know if this package is still actively maintained? If yes, is it possible to use the latest Angular version (14) for the peer dependencies?

Greets

AuthGuard Problem - Services not initialized yet when checking permission

Hi, I tried to follow the documentation and created my own Guard to check the user has permissions to see one specific page, this is what I have in my routing module:

const routes: Routes = [
  {
    path: '',
    component: PurchaseComponent,
    canActivate: [KeycloakPermissionGuard],
    data: {
      permissions: [
        {
          rsname: 'purchase',
          scope: 'action'
        }
      ]
    }
  }
];

And this is my code in the KeycloakPermissionGuard guard:

   if (!this.authenticated) {
      this.keycloakService.login();
      return;
    }

    const requiredRoles = route.data.roles;
    const requiredPermissions = route.data.permissions;

    if (!(requiredPermissions && requiredPermissions.length > 0) && !(requiredRoles && requiredRoles.length > 0)) {
      return resolve(true);
    }

    let granted: boolean = true;

    if (requiredRoles) {
      let roles = this.keycloakService.getUserRoles();
      granted = requiredRoles.every(r => roles.indexOf(r) > -1);
    }

    if (granted && requiredPermissions) {
      for (const requiredPermission of requiredPermissions) {
        if (!this.keycloakAuthorization.checkAuthorization(requiredPermission)){
            granted = false;
            break;
        }
      }
    }

    resolve(granted);

While debugging in the browser, I noticed the guard got activated a lot of times, and every time it went it the 'not authenticated' if, and tried to log in into keycloak again and again. When the guard got activated, the keycloakService and keycloakAuthorizationService, where not initialized yet, and the token was not loaded, thus no permissions, at the end, after waiting for long, those services got initialized, and finally evaluated the permissions. So I wonder if I'm doing something wrong, or this is a bug in the library? How could I get rid of that problem? I would like to use permissions to check if user should see one specific page or get forbidden display shown.

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.