-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Support transforming authorized scopes when the OAuth2Authorization object is created #1504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@Kehrlann How did you register |
@Suvink excellent question, this is a classic pattern, but not 100% obvious. You register it with the @Configuration
class SecurityConfiguration {
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
return http
.authorizeHttpRequests(authorize -> {
// ...
})
// ...
.with(
new OAuth2AuthorizationServerConfigurer(),
authServer -> {
authServer.withObjectPostProcessor(new AuthorizationCodeAuthenticationProvider());
// ...
})
.build();
}
class AuthorizationCodeAuthenticationProvider implements ObjectPostProcessor<AuthenticationProvider> {
@Override
public <O extends AuthenticationProvider> O postProcess(O object) {
if (object instanceof OAuth2AuthorizationCodeRequestAuthenticationProvider) {
return (O) new AppSsoAuthorizationCodeRequestAuthenticationProvider(object, authorizationService);
} else if (object instanceof OAuth2AuthorizationConsentAuthenticationProvider) {
return (O) new AppSsoAuthorizationCodeRequestAuthenticationProvider(object, authorizationService);
}
return object;
}
}
} |
Perfect. Initially we tried to register this with web security config but it didn't work. Then registered it with auth server configs and it works perfectly fine. |
The intended way to wrap the providers is: http
// ...
.with(authorizationServerConfigurer, config -> config
.authorizationEndpoint(endpoint -> endpoint
.authenticationProviders(providers -> providers
.replaceAll(provider -> new MyDelegatingProvider(provider))
// ... Another way to solve this problem may be to filter the requested scopes in a custom |
Context
We have a use-case for filtering the scopes that go into an
access_token
, based on the Resource Owner's "roles" - e.g., if you have the rolehr-user
you can havepayslip.view
in the scopes of access tokens issued for you, but not thepayslip.edit
scope - even if the Client is allowed to request it.There is no way to easily change the
OAuth2Authorization#authorizedScopes()
before it is created/saved.The token itself, when it is a JWT, can be customized with an
OAuth2TokenCustomizer<JwtEncodingContext>
that acts on the scope claim, but the token response has the full list of authorized scopes.Expected Behavior
When the
OAuth2Authorization
object is created and saved in theOAuth2Service
, either throughOAuth2AuthorizationCodeRequestAuthenticationProvider
orOAuth2AuthorizationConsentAuthenticationProvider
, I want to be able to alter the scopes.Current workaround
Currently, we work around this by creating a custom
AuthenticationProvider
that wraps around bothOAuth2AuthorizationCodeRequestAuthenticationProvider
andOAuth2AuthorizationConsentAuthenticationProvider
:The text was updated successfully, but these errors were encountered: