gpt4 book ai didi

rest - Grails 3应用程序中使用Spring Security Rest对 “refresh_token”请求的403响应

转载 作者:行者123 更新时间:2023-12-02 15:17:10 25 4
gpt4 key购买 nike

我在Grails 3应用程序中使用Spring Security Rest发出“refresh_token”请求时遇到了一些麻烦。我有一个同时具有Web前端和一些Rest端点的应用程序,其他所有东西似乎都运行良好。该Web应用程序的行为符合预期,当我通过curl发出登录请求时,

curl -i -X POST localhost:8080/api/login \
-H "Content-Type: application/json" \
-d '{"username":"johndoe", "password":"johndoepassword"}'

我得到了预期的响应(我已将 token 截断了):
{
"username":"johndoe",
"roles":["ROLE_USER"],
"token_type":"Bearer",
"access_token":"eyJhbGciOiJIUzI1NiJ9.xxxxxx",
"expires_in":3600,
"refresh_token":"eyJhbGciOiJIUzI1NiJ9.xxxx"
}

在实际的应用程序中,我可以将access_token添加到 header 中,并在 session 持续时间内毫无问题地进行身份验证。但是,当我点击“刷新 token ”端点时,我得到403
curl -i -X POST localhost:8080/oauth/access_token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=refresh_token&refresh_token=eyJhbGciOiJIUzI1NiJ9.xxxx"

在文档中,这一切看起来都非常简单,但是我显然做错了什么。我认为这是我的配置文件的相关部分:
grails.plugin.springsecurity.controllerAnnotations.staticRules = [
[pattern: '/error', access: ['permitAll']],
[pattern: '/login', access: ['permitAll']],
[pattern: '/login/**', access: ['permitAll']],
[pattern: '/oauth/**', access: ['permitAll']],
[pattern: '/user/register', access: ['permitAll']],
[pattern: '/user/register/**', access: ['permitAll']],
[pattern: '/user/submitRegistration', access: ['permitAll']],
[pattern: '/logoff', access: ['permitAll']],
[pattern: '/shutdown', access: ['permitAll']],
[pattern: '/assets/**', access: ['permitAll']],
[pattern: '/**/js/**', access: ['permitAll']],
[pattern: '/**/css/**', access: ['permitAll']],
[pattern: '/**/images/**', access: ['permitAll']],
[pattern: '/**/favicon.ico', access: ['permitAll']],
[pattern: '/surveyAdmin/**', access: ['ROLE_ADMIN']] ,
[pattern: '/**', access: ['ROLE_USER']]
]

grails.plugin.springsecurity.filterChain.chainMap = [
[pattern: '/assets/**', filters: 'none'],
[pattern: '/**/js/**', filters: 'none'],
[pattern: '/**/css/**', filters: 'none'],
[pattern: '/**/images/**', filters: 'none'],
[pattern: '/**/favicon.ico', filters: 'none'],

[
pattern: '/api/**',
filters: 'JOINED_FILTERS,-anonymousAuthenticationFilter,-exceptionTranslationFilter,-authenticationProcessingFilter,-securityContextPersistenceFilter,-rememberMeAuthenticationFilter'
],

[
pattern: '/rest/**',
filters: 'restTokenValidationFilter,restExceptionTranslationFilter,filterInvocationInterceptor'
],
[pattern: '/**', filters: 'JOINED_FILTERS']
]

有人可以建议通过这里的方法吗?

谢谢,
亚历克斯

最佳答案

通常,我在发布问题后不久就找到了答案。我正在使用实现org.springframework.security.core.userdetails.UserDetails的自定义用户类,但不扩展org.springframework.security.core.userdetails.User。该插件假定主体可以强制转换为“User”对象,这导致用户查找/ token 生成失败。更改我的自定义类以扩展User或重写插件中的refreshToken方法以接受我的自定义用户类都可以使工作正常。

关于rest - Grails 3应用程序中使用Spring Security Rest对 “refresh_token”请求的403响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53695281/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com