Fork me on GitHub

Programming, Internet & more

Authentication with Spring Boot, Angular 2 and Keycloak

Category: spring, spring-boot


  • Pankaj says:

    Thanks for writing. Great articlet.

  • Andy says:

    Good article except it doesn’t want to work for me.

    Frontend app appears to start ok.
    Backend app appears to start ok.

    I get the log in page but then after entering the username & pw I get a keycloak error “Unexpected error when handling authentication request to identity provider.”

    There is a stack trace on KC with the following message…

    [] (default task-3) KC-SERVICES0013: Failed authentication: java.lang.RuntimeException: org.keycloak.jose.jwe.JWEException: Illegal key size

    Running KC 3.4.0, Java 1.8 on Windows 10.

  • Celso says:

    Thanks a lot for the great tutorial on keycloak.

    I’m a beginner in spring security and I need help to make my spring boot applications safer.
    I created two simple examples using spring boot:

    1. API (to be secured):
    2. An API Client (which must access the api):

    I would like to use keycloack (OAuth 2.0) to protect the API and grant access to API Client.

    So, I need guidance to:

    1. Configure keycloack (realm, hole, user, etc.);
    2. Set the API configuration (; and
    3. Set the API Client configuration (, configuration classes, etc.).

    Any help would be appreciated.

    Thank you very much.

  • mahesh loya says:

    Thank for the clear and crisp blog,this is really helpful.

    I have created two client in keycloak admin console,in same realm(testRealm).

    front-end client’s ACCESS-TYPE is “Public”.

    Backend client(backendService) ACCESS-TYPE is “Bearer-only”.

    Front-End is working fine and displays tabs based on roles.

    When I try to hit/access backend service call, it gives me below error in browser console-

    Failed to load http://localhost:9099/api/transaction

    Response for preflight has invalid HTTP status code 401.

    I have raised a SO question,can you please help.

  • Satya says:

    Superb, Thanks to you and the keycloak team.

  • tarsidi says:

    Hi, how we can add redirectUri to javascript adapter?

  • Satya says:

    Thanks for this wonderful demo application, if you have time would you be willing to release another version using the httpclient module…

  • Stephane says:

    A sequel showing how to offer the login from within the front end application would be nice.

  • s says:

    If i want to secure the spring url for nobody can access it then how in keycloak

  • Poorna says:

    down vote
    I have an angular-cli application (angular version 4.0.0). I want to be able to access my environment variables in the environment.ts file created from the cli.


    export SOME_VARIABLE=exampleValue
    When I build my angular app I want “exampleValue” to be populated in the SOME_VARIABLE field.

    // environment.ts

    export const environment = {
    production: false,
    Unfortunately, process.env isn’t available in this file. How can I gain access to it?

  • flx says:

    Thank you very much for this great tutorial!
    Got it working on a minikube in less than 20 minutes.

  • Kristjan Grm says:

    in new versions of angular there is no more @angular/http.. there is nov a @angular/common/http which doesn’t have all the functions of http… any ideas how to port that service part to newest angular?

1 Trackback

Leave a Reply

Your email address will not be published. Required fields are marked *