[英]Auth0 right way to call userinfo
我已經創建了一個具有RS256簽名算法的API,並以http:// localhost:3000 / api / v1作為標識符(受眾),並且將openid,phone,配置文件添加為所創建API的范圍
然后創建一個使用RS256簽名的調用上述API的應用程序,並關閉OIDC Conformant,因為我使用的是自定義登錄頁面。
我能夠成功調用以下授權請求:
https://hostname.auth0.com/authorize?client_id=CLIENT_ID&redirect_uri=http://localhost:4200/dashboard&response_type=code&scope=openid%20profile&state=state&nonce=nonce&audience=https://hostname.auth0.com/userinfo
獲得代碼后,我能夠執行令牌調用並收到了access_token
curl --request POST \ --url https://hostname.auth0.com/oauth/token \ --header 'content-type: application/json' \ --data '{"client_id":"CLIENT_ID","client_secret":"CLIENT_SECRET","audience":"localhost:3000/api/v1","grant_type":"client_credentials","code": "CODE"}'
但是在解碼了JWT令牌后,我在觀眾字段中看不到userinfo端點
因此,在執行以下userinfo調用時遇到了未經授權的錯誤,但是我可以使用給定的訪問令牌調用其他API(受保護的資源)而沒有任何問題。
curl --request GET \
--url 'https://hostname.auth0.com/userinfo' \
--header 'authorization: Bearer {ACCESS_TOKEN}' \
--header 'content-type: application/json'
未經授權
-然后,我嘗試使用userinfo url作為受眾群體值來調用令牌端點:
curl --request POST \
--url https://hostname.auth0.com/oauth/token \
--header 'content-type: application/json' \
--data '{"client_id":"CLIENT_ID","client_secret":"CLIENT_SECRET","audience":"https://hostname.auth0.com/userinfo","grant_type":"client_credentials","code": "CODE"}'
然后我得到以下錯誤:
{"error":"access_denied","error_description":"Client is not authorized to access \"https://hostname.auth0.com/userinfo\". You might probably want to create a \"client-grant\" associated to this API. See: https://auth0.com/docs/api/v2#!/Client_Grants/post_client_grants"}
當我在創建API時嘗試將userinfo url作為附加標識符(受眾群體)添加時,出現了一條錯誤消息,提示“保留了提供的標識符”
請讓我知道我在做什么錯。 期待你的回復。
謝謝。
我在您的工作中遇到多個問題。
如果您還希望獲取API的訪問令牌,則應在初始/authorize
調用中將該API的標識符指定為audience
。 /userinfo
是假定的讀者,因此您無需特別提及。 例如,如果您的API標識符是https://api.example.com
:
https://hostname.auth0.com/authorize?client_id=CLIENT_ID&redirect_uri=http://localhost:4200/dashboard&response_type=code&scope=openid%20profile&state=state&nonce=nonce&audience=https://api.example.com
您可能還需要在上述調用中指定API中定義的某些范圍(除了openid
和profile
)。
當您將代碼交換為令牌時,grant_type應該為authorization_code
(而不是client_credentials
)。 同樣,在此代碼交換期間,您無需再次指定受眾。 但也請確保在此也指定在初始/authorize
請求中發送的redirect_uri
。 這是防止某些攻擊媒介所必需的。
根據以上幾點更改API調用,應將正確的訪問令牌發送回給您-該令牌可用於調用您的API和/userinfo
端點。
有關此流程的更多信息,請參見docs: https : //auth0.com/docs/api-auth/tutorials/authorization-code-grant
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.