I want to make an authorization server on springboot with opaque token to do the validation and storing the access token, refresh token and authorization code on the database. is there a way to configure it using spring-boot-starter-oauth2-authorization-server, Since spring security works under the hood and store it to memory, how could i possibly do the validation and store to the database
@Configuration
@EnableWebSecurity
public class SecurityConfig {
@Bean
@Order(1)
public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
OAuth2AuthorizationServerConfiguration.applyDefaultSecurity(http);
http.getConfigurer(OAuth2AuthorizationServerConfigurer.class)
.oidc(Customizer.withDefaults());
http
.exceptionHandling(httpSecurityExceptionHandlingConfigurer -> httpSecurityExceptionHandlingConfigurer.defaultAuthenticationEntryPointFor(
new LoginUrlAuthenticationEntryPoint("/login"),
new MediaTypeRequestMatcher(MediaType.TEXT_HTML)
))
.oauth2ResourceServer((resourceServer) -> resourceServer
.jwt(Customizer.withDefaults()));
return http.build();
}
@Bean
@Order(2)
public SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http)
throws Exception {
http
.authorizeHttpRequests((authorize) -> authorize
.anyRequest().authenticated()
)
// Form login handles the redirect to the login page from the
// authorization server filter chain
.formLogin(Customizer.withDefaults());
return http.build();
}
@Bean
public UserDetailsService userDetailsService() {
UserDetails userDetails = User
.withUsername("user")
.password("password")
.authorities("read").build();
return new InMemoryUserDetailsManager(userDetails);
}
@Bean
public PasswordEncoder passwordEncoder(){
return new BCryptPasswordEncoder();
}
@Bean
public JwtDecoder jwtDecoder(JWKSource<SecurityContext> jwkSource) {
return OAuth2AuthorizationServerConfiguration.jwtDecoder(jwkSource);
}
@Bean
public AuthorizationServerSettings authorizationServerSettings() {
return AuthorizationServerSettings.builder()
.build();
}
}
i figure out how to get the client dynamically from the database, but still confused to validate and store the generated access token, refresh token, and authorization code to database. i get the Hierarchy of the code but confused to implement it on spring security oauth2 authorization server
I expect to
- get the validation based on client from the database (implemented)
- generate the access token, refresh token, and authorization code and store it to database
- validate the generated access token, refresh token, and authorization from user and check it from the database
Thank you
NewbSS is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.