Seb*_*cas 8 spring-security spring-security-oauth2
我是 spring 环境的新手,我刚刚学习 oauth2。有没有办法让授权服务器也成为资源服务器?我正在查看这个新项目https://github.com/spring-projects/spring-authorization-server
一些步骤或示例将不胜感激。我在尝试实现此操作时遇到的第一个问题是资源服务器的提供程序尚未启动。谢谢你!
小智 9
为了使 Spring Authorization Server 成为资源服务器,我按照以下步骤操作:
.oauth2ResourceServer(OAuth2ResourceServerConfigurer::jwt)到您的二阶 SecurityFilterChain 中,以便代码如下所示: @Bean
@Order(2)
public SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests((authorize) ->
authorize
.anyRequest().authenticated()
)
// ADD THIS LINE HERE
.oauth2ResourceServer(OAuth2ResourceServerConfigurer::jwt)
// Form login handles the redirect to the login page from the
// authorization server filter chain
.formLogin(Customizer.withDefaults());
return http.build();
Run Code Online (Sandbox Code Playgroud)
OpenID Connect 1.0 UserInfo Endpoint是在同一服务器中使用两个角色(授权服务器、资源服务器)的示例。这是因为从授权服务器获取的访问令牌直接用于验证对 UserInfo 端点的请求。顺便说一句,我很好奇你这样做的用例是什么。
查看UserInfo 端点测试的此配置,它演示了如何执行此操作。使这项工作有效的主要是将 a 公开JwtDecoder为 an@Bean并issuer-uri从 Spring Boot 应用程序的配置中省略该属性。
| 归档时间: |
|
| 查看次数: |
5963 次 |
| 最近记录: |