Spring Boot:访问此资源需要完全身份验证 [英] Spring Boot: Full authentication is required to access this resource

查看:76
本文介绍了Spring Boot:访问此资源需要完全身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用这篇文章中的 wso2is 服务器做 Spring Boot Security 的例子 https://github.com/angel-git/wso2is-springoauth,当我尝试使用访问令牌访问资源时,我得到 <块引用>

{"error":"unauthorized","error_description":"访问此资源需要完整身份验证"}

我通过以下方式生成访问令牌:

<块引用>

curl -u CLIENT_ID:CLIENT_SECRET-k -dgrant_type=password&username=admin&password=admin"-H内容类型:应用程序/x-www-form-urlencoded"https://localhost:9443/oauth2/token

并通过以下方式访问资源:

<块引用>

curl -H GET "授权:ACCESS_TOKEN"http://localhost:8080/greeting

我在 stackoverflow 上找到了很多解决方案,但不幸的是无法解决我的问题

请帮忙,谢谢

解决方案

非常感谢 Angel Gavalda,他帮助我解决了问题.我使用以下命令生成访问令牌和访问资源

用于生成访问令牌:-

<块引用>

卷曲 -k -d'grant_type=client_credentials&client_id=yourClientId&client_secret=yourClientSecret'https://localhost:9443/oauth2/token

用于访问资源:-

<块引用>

curl -k -H "授权:不记名 $ACCESS_TOKEN"http://localhost:8080/greeting

I am doing example of Spring Boot Security with wso2is server from this post https://github.com/angel-git/wso2is-springoauth, when I am trying to access resource with access token I am getting

{"error":"unauthorized","error_description":"Full authentication is required to access this resource"}

I am generating access token by:

curl -u CLIENT_ID:CLIENT_SECRET-k -d "grant_type=password&username=admin&password=admin" -H "Content-Type:application/x-www-form-urlencoded" https://localhost:9443/oauth2/token

and accessing resources by:

curl -H GET "Authorization: ACCESS_TOKEN" http://localhost:8080/greeting

I found many solution on stackoverflow but unfortunately could not solve my issue

please help, thank you

解决方案

Many thanx to Angel Gavalda who helped me to solved problem. I used following commands to generate access token and access resource

For Generating Access token:-

curl -k -d 'grant_type=client_credentials&client_id=yourClientId&client_secret=yourClientSecret' https://localhost:9443/oauth2/token

For Accessing Resource:-

curl -k -H "Authorization: Bearer $ACCESS_TOKEN" http://localhost:8080/greeting

这篇关于Spring Boot:访问此资源需要完全身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆