Giter VIP home page Giter VIP logo

Comments (7)

wimdeblauwe avatar wimdeblauwe commented on May 20, 2024

Changing it to this makes it compile again:

        return new KeycloakAuthRequestPostProcessor(Optional.of(new SimpleAuthorityMapper()))
                .authorities("user", role)
                .accessToken(accessToken -> {
                    accessToken.setPreferredUsername(email);
                    accessToken.setSubject(authServerUserId);
                    accessToken.setGivenName(givenName);
                    accessToken.setFamilyName(familyName);
                })
                .idToken(idToken -> {
                    idToken.setPreferredUsername(email);
                    idToken.setSubject(authServerUserId);
                    idToken.setGivenName(givenName);
                    idToken.setFamilyName(familyName);
                });

But now my @AuthenticationPrincipal is null in my controller methods. The reason seems to be that instead of a KeycloakAuthenticationToken, a KeycloakPrincipal should be used as the type now. Any idea why this is? And is there a way to use the KeycloakAuthenticationToken?

I use the KeycloakAuthenticationToken because I do token.getAccount().getRoles() at a certain point to retrieve the current user roles.

from spring-addons.

wimdeblauwe avatar wimdeblauwe commented on May 20, 2024

The issue with the null principal is due to spring-projects/spring-framework#26380 If you can confirm that my changes for KeycloakAuthRequestPostProcessor are what they should be then this issue can be closed.

from spring-addons.

ch4mpy avatar ch4mpy commented on May 20, 2024

Hi @wimdeblauwe , as you found out, version 2.3.0 introduced breaking changes in claims declaration.
Sorry for migration effort :/

The motivation was to get closer to OpenID specs.
The motivation for this motivation is to reuse some code from my OpenID Authorization implementation and as so maintain less code.

As you noted, prior to 2.3.0, using .name(email) was setting preferredUsername which was a rather bad idea.
I understand the name from javax.security.Principal as a way to define identity, which is subject in OpenID world.

KeycloakAuthRequestPostProcessor::name was just a shortcut and changing its behavior to set subject instead of preferedUsername (which is a Keycloak private claim) was too confusing IMO. So I just dropped it.

P.S.
keycloak AccessToken extends IDToken, so if you externalize idToken consumer function, you could use it from accessToken one (and avoid the code duplication in your last sample).

from spring-addons.

wimdeblauwe avatar wimdeblauwe commented on May 20, 2024

Ok, thank you for the quick reply. So my changed code is correct?

from spring-addons.

ch4mpy avatar ch4mpy commented on May 20, 2024

It seems good. Doesn't it work as expected ?

from spring-addons.

wimdeblauwe avatar wimdeblauwe commented on May 20, 2024

from spring-addons.

ch4mpy avatar ch4mpy commented on May 20, 2024

Ok, nice.

from spring-addons.

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.