Spring Security OAuth2 终点 check_token

我正在尝试配置资源服务器以使用单独的授权服务器使用 spring security oauth. 我用
RemoteTokenServices

, 这需要终点
/check_token

.

我可以看到终点
/oauth/check_token

默认使用时启用
@EnableAuthorizationServer

. 但是,默认端点不可用。

应该手动将下一个条目添加到此端点的白色列表中吗?


http.authorizeRequests//.antMatchers/"/oauth/check_token"/.permitAll//;


这将使每个人都有这个端点,这是所需的行为吗? 或者我错过了什么。

先感谢您,
已邀请:

小姐请别说爱

赞同来自:

你应该


@Override
public void configure/AuthorizationServerSecurityConfigurer oauthServer/ throws Exception
{
oauthServer.checkTokenAccess/"permitAll//"/;
}


有关它的更多信息 ::

https://coderoad.ru/26250522/

冰洋

赞同来自:

只是为了澄清几个时刻并将一些信息添加到所提供的答案中

普利卡岛沙拉

/和

亚历克斯

在适当的话题中/:

1个方法
configure

通过创建类扩展来重新定义
AuthorizationServerConfigurerAdapter

:


@EnableAuthorizationServer
@Configuration
public class AuthServerConfig extends AuthorizationServerConfigurerAdapter {

@Override
public void configure/AuthorizationServerSecurityConfigurer oauthServer/ throws Exception {
oauthServer.tokenKeyAccess/"permitAll//"/
.checkTokenAccess/"isAuthenticated//"/;
}

@Override
public void configure/ClientDetailsServiceConfigurer clients/ throws Exception {
clients
.inMemory//
.withClient/"ger-client-id"/
.secret/"ger-secret"/
.authorizedGrantTypes/"password"/
.scopes/"read", "write"/;
}
}


第二次建议阅读
https://docs.spring.io/spring- ... erver
Spring, 解释自动设置执行 Spring Boot, 当我们打开注释时
@EnableAuthorizationServer

, 包括鲍勃
AuthorizationServerConfigurer

. 如果您创建配置组件展开
AuthorizationServerConfigurerAdapter

, 正如我上面所做的那样,所有这些自动配置都将被禁用。

3 - 如果自动配置适合您,请符合您 JUST 想要操纵对端点的访问
/oauth/check_token

, 您仍然可以在不创建组件的情况下进行。
AuthorizationServerConfigurer

/因此,不必配置所有软件/.

例如,您需要添加属性。
security.oauth2.authorization.check-token-access

到文件。
application.properties

:


security.oauth2.client.client-id=ger-client-id
security.oauth2.client.client-secret=ger-secret
security.oauth2.client.scope=read,write

security.oauth2.authorization.check-token-access=permitAll//


当然,你可以给它一个值
isAuthenticated//

, 如果你想。

您可以设置日志级别 DEBUG, 要验证所有内容是否正确配置:


16:16:42.763 [main] DEBUG o.s.s.w.a.e.ExpressionBasedFilterInvocationSecurityMetadataSource - Adding web access control expression 'permitAll//', for Ant [pattern='/oauth/check_token']


这些属性没有这么多的文档,但你可以从中找出它们
https://github.com/spring-proj ... 23L28
.

最后一件事值得一提,虽然它似乎在最新版本中得到了修复 Spring, 我刚送了
https://github.com/spring-proj ... /1544
在项目中 spring-security-oauth; 它看起来像一个函数 token_check 默认情况下启用,如果添加斜角 trailing 请求:


$ curl localhost:8080/oauth/check_token/?token=fc9e4ad4-d6e8-4f57-b67e-c0285dcdeb58
{"scope":["read","write"],"active":true,"exp":1544940147,"authorities":["ROLE_USER"],"client_id":"ger-client-id"}

八刀丁二

赞同来自:

首先,表达对配置令牌的访问:


@Override
public void configure/AuthorizationServerSecurityConfigurer securityConfigurer/ throws Exception {
securityConfigurer
.allowFormAuthenticationForClients//
.checkTokenAccess/"isAuthenticated//"/
.addTokenEndpointAuthenticationFilter/checkTokenEndpointFilter///;
}


然后我们需要定义用于处理客户身份验证的过滤器:


@Bean
public ClientCredentialsTokenEndpointFilter checkTokenEndpointFilter// {
ClientCredentialsTokenEndpointFilter filter = new ClientCredentialsTokenEndpointFilter/"/oauth/check_token"/;
filter.setAuthenticationManager/authenticationManager/;
filter.setAllowOnlyPost/true/;
return filter;
}

要回复问题请先登录注册