简体   繁体   English

Spring Security Oauth2:访问令牌无效/过期时的回退

[英]Spring Security Oauth2: Fallback when access token is invalid/expired

I am using Spring Security to protect my endpoints. 我正在使用Spring Security保护我的端点。

My problem is, is it possible to response differently when users are using valid/invalid access token? 我的问题是,当用户使用有效/无效的访问令牌时,响应是否可能有所不同?

For example, for a single /api/info 例如,对于单个/ api / info

(1) When an invalid/expired access token is passed in the request, only very limited information will be returned (1)在请求中传递无效/过期的访问令牌时,将仅返回非常有限的信息
(2) When a valid access token is passed in the request, very customized and rich content is returned according to a different user. (2)在请求中传递有效的访问令牌后,将根据不同的用户返回非常定制且丰富的内容。

I've tried to use access=permitAll() , but it doesn't work because invalid tokens can not pass oauth2 validation. 我尝试使用access=permitAll() ,但是它无效,因为无效令牌无法通过oauth2验证。

Using security="none" is also not working because it will not try to get user info at all. 使用security="none"也不起作用,因为它根本不会尝试获取用户信息。

编写一个自定义的OAuth2AccessDeniedHandler ,然后使用security:access-denied-handler XML标记或类似的Java Config将其插入到/info端点。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring Security + OAuth,如果缺少访问令牌,则进行回退 - Spring Security + OAuth, fallback if access token absent Spring Oauth2无效的访问令牌 - Spring Oauth2 Invalid access token Spring security oauth2 - 无法访问 /oauth/token 路由 - Spring security oauth2 - Can't access /oauth/token route spring security oauth2(2.0.8)获取InMemory令牌库使用的无效访问令牌 - spring security oauth2 (2.0.8) getting Invalid access token used InMemory tokenstore 春季安全oauth2 JWT刷新令牌返回“身份验证失败:invalid_token无法将访问令牌转换为JSON” - spring security oauth2 JWT refresh token returns “Authentication failed: invalid_token Cannot convert access token to JSON” Spring Security + Google OAuth2登录:访问令牌是否为空? - Spring Security + Google OAuth2 Login: access token is null? Spring Boot 2.0.3 Oauth2安全性:即使在标头中使用访问令牌也会出现401错误 - Spring Boot 2.0.3 Oauth2 Security: Getting 401 error even when using access token in header Spring OAuth2 / OAuth /令牌无效凭证 - Spring oauth2 /oauth/token invalid credentials Spring Security Oauth2 客户端获取访问令牌失败,请求代码无效=415,消息=不支持的媒体类型 - Spring Security Oauth2 Client get access token fails with invalid request code=415, message=Unsupported Media Type Spring Security Oauth2:处理过期的AccessToken的流程 - Spring Security Oauth2: Flow to Handling Expired AccessToken
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM