我应该向 /oauth/token、OAuth2 样本提出什么请求才能使用密码授权?
What request should I make to /oauth/token, OAuth2 sample to use password grant?
运行sparklr2
和tonr2
没有问题(代码授权授予),开箱即用,没有任何修改。
想尝试密码授予。使用参数
尝试了 GET
和 POST
?grant_type=password&client_id=my-trusted-client&username=marissa&password=koala
如果我没理解错的话,.withClient("my-trusted-client").authorizedGrantTypes("password",...)
是说这个设置支持密码授予,对吧?
GET
、POST
return 和 http 401, blocked by AnonymousAuthenticationFilter.doFilter(), SecurityContextHolder.getContext().getAuthentication() return null
。
所以,这是否意味着,即使使用 username
和 password
参数,我仍然必须将身份验证(在 base64 中)放在 header 中?或者我做错了什么?
我跟踪spring oauth2
源代码后弄明白了。
即使 username
& password
在 POST
body 中,令牌端点仍然需要身份验证才能访问。
并且对于密码授予,http header 中的身份验证不是 username
& password
(sparklr2 用户),而是必须使用 client_id
和 client_secret
代替。使用 base64 编码 "client_id:secret"
,将其放入请求 header,现在可以访问令牌端点。
运行sparklr2
和tonr2
没有问题(代码授权授予),开箱即用,没有任何修改。
想尝试密码授予。使用参数
尝试了 GET
和 POST
?grant_type=password&client_id=my-trusted-client&username=marissa&password=koala
如果我没理解错的话,.withClient("my-trusted-client").authorizedGrantTypes("password",...)
是说这个设置支持密码授予,对吧?
GET
、POST
return 和 http 401, blocked by AnonymousAuthenticationFilter.doFilter(), SecurityContextHolder.getContext().getAuthentication() return null
。
所以,这是否意味着,即使使用 username
和 password
参数,我仍然必须将身份验证(在 base64 中)放在 header 中?或者我做错了什么?
我跟踪spring oauth2
源代码后弄明白了。
即使 username
& password
在 POST
body 中,令牌端点仍然需要身份验证才能访问。
并且对于密码授予,http header 中的身份验证不是 username
& password
(sparklr2 用户),而是必须使用 client_id
和 client_secret
代替。使用 base64 编码 "client_id:secret"
,将其放入请求 header,现在可以访问令牌端点。