带有泽西岛的Spring Oauth 2.0:输入正确的凭据后,未经授权的响应401
这是我的问题:当我尝试调用此方法时,我得到了这个错误
InboundJaxrsResponse{
context=ClientResponse{method=POST,
uri=http://localhost:9001/oauth/token, status=401,
reason=Unauthorized}}
public String getToken() {
String grant_type ="client_credentials";
String client_id = "abcd";
String client_secret = "mpoo";
Form form = new Form();
form.param("grant_type",grant_type);
form.param("client_id",client_id);
form.param("client_secret",client_secret);
JerseyClientBuilder jerseyClientBuilder = new JerseyClientBuilder();
JerseyWebTarget jerseyWebTarget =
jerseyClientBuilder.build().target("http://localhost:9001/oauth/token");
Response response = jerseyWebTarget.request().post(Entity.form(form));
return response.toString();
}
吗?
Here is my problem: when I try to call this method, I got this error
InboundJaxrsResponse{
context=ClientResponse{method=POST,
uri=http://localhost:9001/oauth/token, status=401,
reason=Unauthorized}}
public String getToken() {
String grant_type ="client_credentials";
String client_id = "abcd";
String client_secret = "mpoo";
Form form = new Form();
form.param("grant_type",grant_type);
form.param("client_id",client_id);
form.param("client_secret",client_secret);
JerseyClientBuilder jerseyClientBuilder = new JerseyClientBuilder();
JerseyWebTarget jerseyWebTarget =
jerseyClientBuilder.build().target("http://localhost:9001/oauth/token");
Response response = jerseyWebTarget.request().post(Entity.form(form));
return response.toString();
}
Any Answer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是发送令牌请求的正确方法。查看 for Client_credentials grant type 。请求的正确格式如下:
因此,只有
Grant_Type
才能是form>表单
正文的一部分。client_id
和client_secret
应该是 base644 编码并用于基本身份验证:That's not the correct way to send the token request. Look at the RFC for client_credentials grant type. The correct format for the request is as follows:
So only the
grant_type
should be a part of theForm
body. Theclient_id
andclient_secret
should be Base64 encoded and used for Basic Authentication: