GithubHelp home page GithubHelp logo

keycloak-angular-17-example's Introduction

Keycloak Angular Example

main-screen

This project was generated with Angular CLI version 17.3.6.

Development server

Run ng serve for a dev server. Navigate to http://localhost:4200/. The application will automatically reload if you change any of the source files.

Keycloak Integration

  1. There should be a running keycloak instance (Keycloak version 22 is used for testing this implementation)
  2. Create a client inside the Keycloak server as mentioned in Keycloak Client Info section
  3. Provide the config details of the created client as config properties for the keycloak client initialization function (see app.config.ts file)
  4. Start the angular app

Keycloak Client Info

client image 1

client image 2

Disable unnecessary redirect URIs and web origins (if exist) when running on production mode.
By Default SHA256 based Proof key for code exchange (PKCE) method is enabled

Functions (Buttons) of the App

Authenticated

Check whether the user is already logged into the system. Indicated as true or false

Login

Initiate the login process. (User will be redirected to the Keycloak loging page)

Copy Access Token

Copy the access token to the clipboard

Parse Access Token

Show the parsed access token in the status panel

Token expired in 10 seconds

Check whether the token is going to expire within 10 seconds. Using the keycloak angular sdk provided function

this.keycloakService.isTokenExpired(n) if the token is going to expire within n seconds, this will return true

Update token (if gonna expire)

This function is also working in a similar way to isTokenExpired method. This function will update the token if it is going to expire within the given number of seconds.

Send HTTP Request

Send a request to the given mockbin url. This HTTP request contains the received access token as a bearer token.

Logout

Logout the user from the system.

Show Assigned Roles

Show all the assigned roles to the user including both realm roles and client roles.

Similarly you can use the function this.keycloakService.isUserInRole('role name') to directly check whetehr a particular user has a specific role assigned.

Important !!! When using single page apps (client-side applications), the client has to be a public client as there is no secure way to store client credentials in a client-side application. This consideration makes it very important to make sure the redirect URIs you have configured for the client are correct and as specific as possible.

You also need to configure Valid Redirect URIs and Web Origins. Be as specific as possible as failing to do so may result in a security vulnerability.

References

keycloak-angular-17-example's People

Contributors

hexadefence avatar

Watchers

Tharindu Nishada avatar  avatar

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.