Spring Authorization Server: Authorized Scopes missing from token and from context.getAuthorizations()

I have a Spring Authorization Server 1.2.0 project where I have access to a RegisteredClient that has scopes profile and read.custom.scope. This client has grant types refresh_token and authorization_code. The authorizations are being persisted to the DB with appropriate repositories etc.

Up until recently I had no need for scopes in the token. When going to use them I realised the token doesn’t have authorized scopes.

To remedy this I configured an OAuth2TokenCustomizer to add the consented scopes to the token as an authorities claim.

    @Bean
    public OAuth2TokenCustomizer<JwtEncodingContext> oAuth2TokenCustomizer() {

        return context -> {
            OAuth2Authorization oAuth2Authorization = context.getAuthorization();

            context.getClaims().claim( "authorities", oAuth2Authorization.getAuthorizedScopes() );
        };
    }

However, this did not work as the oAuth2Authorization.getAuthorizedScopes() returns an empty Collection. I now see an empty array of authorities in the accessToken.

I have checked that my RegisteredClient has the correct scopes and ensured that conversion between RegisteredClient -> ClientEntity and ClientEntity -> RegisteredClient hasn’t lost this scope information along the way.

The persisted authorization entry also has an empty value for the accessTokenScopes property.

I’m able to debug the OAuth2AuthorizationEndpointFilter and can see that the authentication object in the filter has the correct scopes I’d expect to see.

I have a JwtDecoder that I use for an external inbond mechanisim for authentication (rather than using formLogin):


@Bean
    @Order(2)
    public SecurityFilterChain standardSecurityFilterChain(HttpSecurity http) throws Exception {
...
                .oauth2ResourceServer(configurer -> {
                    configurer.jwt(jwtConfigurer -> jwtConfigurer.decoder( ssoAuthenticationJwtDecoder() ));
                });
        http.csrf().disable();


        return http.build();
    }

    @Bean(name = "jwtDecoder")
    public JwtDecoder ssoAuthenticationJwtDecoder() {
        return new CustomJwtDecoder();
    }

I then have a JwtDecoder that’s used for the OAuth Authorization Server:

    @Bean
    public JwtDecoder jwtDecoder(JWKSource<SecurityContext> jwkSource) {
        return OAuth2AuthorizationServerConfiguration.jwtDecoder(jwkSource);
    }

I’m not sure the JWT decoder stuff is the issue here but it’s weird so thought I’d include it for context.

The big question: How can I ensure that the consented scopes become authorizedScopes that will be available when I call context.getAuthorizedScopes()?

Any and all pointers and help greatly welcome.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

Spring Authorization Server: Authorized Scopes missing from token and from context.getAuthorizations()

I have a Spring Authorization Server 1.2.0 project where I have access to a RegisteredClient that has scopes profile and read.custom.scope. This client has grant types refresh_token and authorization_code. The authorizations are being persisted to the DB with appropriate repositories etc.

Up until recently I had no need for scopes in the token. When going to use them I realised the token doesn’t have authorized scopes.

To remedy this I configured an OAuth2TokenCustomizer to add the consented scopes to the token as an authorities claim.

    @Bean
    public OAuth2TokenCustomizer<JwtEncodingContext> oAuth2TokenCustomizer() {

        return context -> {
            OAuth2Authorization oAuth2Authorization = context.getAuthorization();

            context.getClaims().claim( "authorities", oAuth2Authorization.getAuthorizedScopes() );
        };
    }

However, this did not work as the oAuth2Authorization.getAuthorizedScopes() returns an empty Collection. I now see an empty array of authorities in the accessToken.

I have checked that my RegisteredClient has the correct scopes and ensured that conversion between RegisteredClient -> ClientEntity and ClientEntity -> RegisteredClient hasn’t lost this scope information along the way.

The persisted authorization entry also has an empty value for the accessTokenScopes property.

I’m able to debug the OAuth2AuthorizationEndpointFilter and can see that the authentication object in the filter has the correct scopes I’d expect to see.

I have a JwtDecoder that I use for an external inbond mechanisim for authentication (rather than using formLogin):


@Bean
    @Order(2)
    public SecurityFilterChain standardSecurityFilterChain(HttpSecurity http) throws Exception {
...
                .oauth2ResourceServer(configurer -> {
                    configurer.jwt(jwtConfigurer -> jwtConfigurer.decoder( ssoAuthenticationJwtDecoder() ));
                });
        http.csrf().disable();


        return http.build();
    }

    @Bean(name = "jwtDecoder")
    public JwtDecoder ssoAuthenticationJwtDecoder() {
        return new CustomJwtDecoder();
    }

I then have a JwtDecoder that’s used for the OAuth Authorization Server:

    @Bean
    public JwtDecoder jwtDecoder(JWKSource<SecurityContext> jwkSource) {
        return OAuth2AuthorizationServerConfiguration.jwtDecoder(jwkSource);
    }

I’m not sure the JWT decoder stuff is the issue here but it’s weird so thought I’d include it for context.

The big question: How can I ensure that the consented scopes become authorizedScopes that will be available when I call context.getAuthorizedScopes()?

Any and all pointers and help greatly welcome.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật