我有一個後端API,我想通過使用Azure API Management進行代理。 這個後端API需要我提供一個Bearer Oauth2標記。 我想使用Azure APIM爲我處理Oauth2流程,並且我想公開一個將被客戶端應用程序使用的非常簡單的API。我想避免我的客戶端應用程序使用Oauth2。 我該如何處理APIM?我發現很多示例演示瞭如何使用Oauth2保護後端API,但這不是我嘗試實現的用例。 謝謝。Azure API管理:Oauth2與後端API
1
A
回答
0
您需要做的是添加一個標頭來請求 - 使用set-header策略將授權標頭設置爲所需的值。如果您可以在策略中硬編碼令牌,那將很好。
如果你不能 - 你必須使用發送請求來組織OAuth流策略。簡而言之,您要做的是將您的應用ID和密碼發送給OAuth端點,並解析其響應以獲取令牌並將其附加到請求。
1
這裏是一個政策片段,使這項工作:
<send-request ignore-error="true" timeout="20" response-variable-name="bearerToken" mode="new">
<set-url>{{authorizationServer}}</set-url>
<set-method>POST</set-method>
<set-header name="Content-Type" exists-action="override">
<value>application/x-www-form-urlencoded</value>
</set-header>
<set-body>
@{
return "client_id={{clientId}}&resource={{scope}}&client_secret={{clientSecret}}&grant_type=client_credentials";
}
</set-body>
</send-request>
<set-header name="Authorization" exists-action="override">
<value>
@("Bearer " + (String)((IResponse)context.Variables["bearerToken"]).Body.As<JObject>()["access_token"])
</value>
</set-header>
<!-- We do not want to expose our APIM subscription key to the backend API -->
<set-header exists-action="delete" name="Ocp-Apim-Subscription-Key"/>
很快從APIM團隊APIM政策片斷分公司
相關問題
- 1. Azure API管理 - API端點域與實際API URL
- 2. 使後端API僅可通過Azure API管理訪問
- 3. Azure API管理和ASMX/WSDL SOAP端點?
- 4. Azure API管理服務API創建
- 5. Azure API管理REST API用戶
- 6. 使用Azure API管理創建API
- 7. Azure API管理和HMAC
- 8. Azure API管理響應404
- 9. Azure API管理至VNet
- 10. Azure API管理密鑰
- 11. Azure api管理SOAP-To-REST
- 12. WSO2 API管理器後端url
- 13. 保護在Azure的API管理所有的API與AD
- 14. 使用Azure AAD對Azure服務管理API進行身份驗證OAuth2
- 15. 與WSO2 API管理
- 16. OAuth2與雅虎API
- 17. 當Azure Active Directory Oauth2 V2.0端點將提供將支持Azure資源管理器API的access_code時?
- 18. 我可以使用azure oauth2客戶端憑據流訪問經典的azure服務管理rest api嗎?
- 19. 後端https服務器如何與WSO2 API管理器連接
- 20. 在Azure Api管理中保護WebApi
- 21. Azure API管理訂閱到期
- 22. Azure管理API產生403錯誤
- 23. Azure管理API中的驗證問題
- 24. Azure服務管理api更改配置
- 25. Azure API管理 - 範圍聲明NULL
- 26. 用於.Net的Azure服務管理API
- 27. 通過Azure API管理流式傳輸
- 28. Azure Api管理中的可選參數
- 29. 使用Azure資源管理器REST API