Spring Boot 2 / Spring Security 5:无法获取OAUTH2令牌

时间:2018-03-18 22:52:57

标签: spring-boot spring-security-oauth2

框架:Spring Boot 2(Spring 5)

我按照on the Spring Boot 2 documentation的说明,了解如何提供提供OAUTH2令牌的服务。

你可以在GitHub上看到这里的代码。 (编辑:链接被删除。更新该分支后它不再有效。)

无论我发送给/oauth/token的密码/用户ID /密码是什么,我都会得到一封带有纯文本回复的403:CSRF Token has been associated to this client

示例:

$ curl client:secret@localhostlocalhost:8080/oauth/token -d grant_type=password - d username=user -d password=pwd -v
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8080 (#0)
* Server auth using Basic with user 'client'
> POST /oauth/token HTTP/1.1
> Host: localhost:8080
> Authorization: Basic Y2xpZW50OnNlY3JldA==
> User-Agent: curl/7.54.0
> Accept: */*
> Content-Length: 46
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 46 out of 46 bytes
< HTTP/1.1 403 Forbidden
< transfer-encoding: chunked
< Content-Type: text/plain
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: 0
< X-Content-Type-Options: nosniff
< X-Frame-Options: DENY
< X-XSS-Protection: 1 ; mode=block
<
* Connection #0 to host localhost left intact
CSRF Token has been associated to this client%

整体反应是个谜。

任何帮助将不胜感激。我是Spring Framework的新手,发现很难获得工作教程或参考资料。我希望这是&#34;愚蠢的&#34;我还没见过。

非常感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

该解决方案可在this Pull Request中找到。

另外,我的初始代码中的一个核心问题是@Configuration类没有声明任何package,这确实使它们超出了Spring的启动扫描范围。