Git Product home page Git Product logo

Comments (2)

jgrandja avatar jgrandja commented on May 18, 2024

Closing this as a duplicate of gh-790.

@git9999999

If an application needs to override the default 30min expiry for an ID Token, you can use an OAuth2TokenCustomizer to override the default.

from spring-authorization-server.

git9999999 avatar git9999999 commented on May 18, 2024

Just for documentation, so other peoples have the code ready to fix this problem, here how i fix this issue.

this line did the fix
context.getClaims().claim("exp", Instant.now().plus(14, HOURS));

@Bean
    public OAuth2TokenCustomizer<JwtEncodingContext> tokenCustomizer() {
        return context -> {
            var principal = context.getPrincipal();
            if (Objects.equals(context.getTokenType().getValue(), "access_token") && principal instanceof UsernamePasswordAuthenticationToken) {
                var user = (User) principal.getPrincipal();
                context.getClaims().claim("preferred_username", user.getUsername());
                context.getClaims().claim(USER_ID_CLAIM_KEY.getKey(), user.getUsername());
                context.getClaims().claim("groups", List.of(AZURE_AD_GROUP_AAA_DEV_ADMINPORTAL));
                context.getClaims().claim("correlationId", UUID.randomUUID().toString());
            }
            if (context.getTokenType().getValue().equals(OidcParameterNames.ID_TOKEN)) {
                var user = (User) principal.getPrincipal();
                context.getClaims()
                    .claim("preferred_username", user.getUsername());
                // Overwrite the exp of the ID TOKEN so the tester can longer test
                context.getClaims().claim("exp", Instant.now().plus(14, HOURS));
                context.getClaims().claim("groups", List.of(AZURE_AD_GROUP_AAA_DEV_ADMINPORTAL));
            }
        };
    }

from spring-authorization-server.

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.