pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

如何使用 Azure Active Directory 授權的 Azure REST API 應

How to consume Azure REST API App with Azure Active Directory authorization On(如何使用 Azure Active Directory 授權的 Azure REST API 應用程序)
本文介紹了如何使用 Azure Active Directory 授權的 Azure REST API 應用程序的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我已將 API 應用程序 部署到 Azure,但如果身份驗證(使用 AAD)設置為 ON,我在創建 API 客戶端時遇到問題.

I have deployed an API App to Azure, but I am having problems creating API Client if Authentication (with AAD) is set to ON.

當我嘗試生成服務客戶端時(當身份驗證關閉時),然后生成客戶端代碼(使用 Autorest 完成)并且代碼正在工作,但是當我打開身份驗證時(以及請求未通過身份驗證時采取的操作是設置為 使用 Azure Active Directory 登錄),然后

When I try to generate service client (when Authentication is OFF), then client code is generated (it's done with Autorest) and code is working, but when I switch Authentication ON (and Action to take when request is not authenticated is set to Login with Azure Active Directory), then

1) 服務調用返回401 Unauthorized(沒有重定向到AAD登錄頁面)

1) service call returned 401 Unauthorized (without redirecting to AAD login page)

2) 然后我嘗試再次生成服務客戶端(從項目的上下文菜單 -> 添加 -> REST API 客戶端 -> 然后在對話框中我選擇選擇 Azure 資產"并按確定并收到一條消息 無法下載 Microsoft Azure API 應用程序的元數據文件:...應用程序名稱..."(并且沒有可用的其他信息")

2) Then I tried to generate service client once more (from Project's context menu -> Add -> REST API Client -> then in the dialog box I chose "Select Azure Asset" and pressed OK and got a message "Failed to download metadata file for Microsoft Azure API App: ...app name..." (and "no additional information available")

我正在根據此 Azure 手冊實施 AAD(使用快速設置):

I was implementing AAD according to this Azure manual (using express settings):

https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-how-to-configure-active-directory-authentication/

也按照此視頻工作,并且此視頻中顯示的所有內容都正常工作,除了 AAD 沒有被演示......而且對我來說它不起作用......

Was working according to this video, too and everything what is shown in this video was working, except that AAD was not demonstrated... and for me it's not working...

https://azure.microsoft.com/en-us/documentation/videos/connect-2015-what-s-new-in-app-service-api-apps/

有什么建議嗎?

編輯

1) 如果我在 Web 瀏覽器中輸入請求 url(REST API 客戶端使用),那么它會返回有效結果2) 我發現我正在使用沒有憑據的 REST API(我認為在這種情況下應該顯示 Azure AD 登錄屏幕......但事實并非如此)

1) If I enter the request url (that REST API client uses) in web browser - then it returns valid results 2) I found out that I am using REST API without credentials (I thought Azure AD login screen should be presented in this case... but it isn't)

編輯 2

我取得了一些進展 - 進入了 AAD 登錄屏幕,但在輸入憑據后我得到 bearer token,但是當我嘗試查詢服務時,我收到一條錯誤消息:

I got some progress - got to the AAD login screen, but after entering credentials I get the bearer token, but when I try to query the service, I get an error message:

AADSTS65005:客戶端應用程序已請求訪問資源https....azurewebsites.net".此請求失敗,因為客戶端未在其 requiredResourceAccess 列表中指定此資源.跟蹤 ID:4176e...相關 ID:1d612d...時間戳:2016-11-13 18:28:34Z

這些是我已經完成的步驟:

These are the steps I've done to get this far:

0) 將 Microsoft.IdentityModel.Clients.ActiveDirectory nuget 包添加到客戶端項目

0) Added Microsoft.IdentityModel.Clients.ActiveDirectory nuget pack to client project

1) 在 Azure Active Directory 中注冊我的客戶端應用

1) registered my client app in Azure Active Directory

2) 從客戶端應用程序調用 REST API 時,我正在添加 ServiceClientCredentials

2) when calling REST API from client application, I am adding ServiceClientCredentials

3) 在創建 ServiceClientCredentials 時,我提供了 4 個元素-authority = 這是來自 AAD 應用注冊 -> Endpoints => Federation Metadata Document vērtība(沒有起始部分 http://login.windows.net/)

3) when creating ServiceClientCredentials I provide 4 elements -authority = this is from AAD App registrations -> Endpoints => Federation Metadata Document vērtība (without the starting part http://login.windows.net/)

-resource => 這是 REST API uri(=>作為請求令牌接收者的目標資源的標識符)

-resource => this is REST API uri (=>Identifier of the target resource that is the recipient of the requested token)

-clientId => 這是我在 AAD 中注冊客戶端應用程序后獲得的應用程序 ID-redirect Uri => 因為我的客戶端應用程序是本機應用程序,所以這只是任何有效的 url

-clientId => this is application id I get after I registered client app in AAD -redirect Uri => since my client app is a Native application, then this is just any valid url

如何在我的客戶端應用程序中指定此資源?

客戶端未在其 requiredResourceAccess 列表中指定此資源

推薦答案

我設法找到了有關如何啟用對 Azure REST API 應用程序的 AAD 授權的解決方案.以防萬一有人遇到同樣的挑戰,我希望這會有所幫助.

I managed to find a solution on how to enable AAD authorization to Azure REST API App. Just in case anyone has the same challenge, I hope this will be helpful.

這些是我執行的步驟:

1) 在應用服務中 -> 認證/授權

1) In App services -> Authentication/authorization

  • 應用服務身份驗證 => 開啟
  • 請求未通過身份驗證時采取的措施 => 使用 AAD 登錄
  • 使用 Express 設置配置 AAD(您必須在此處創建 Azure為您的 API 應用程序的廣告應用程序 - 即您的服務的應用程序注冊")

2) 在 Azure Active Directory -> 應用注冊

2) In Azure Active Directory -> App registrations

  • 為您的客戶端應用添加注冊
  • 編輯客戶端應用程序的清單 - 在 requiredResourceAccess 部分中,您必須添加有關 REST API 應用程序的信息:
    • resourceAppId -> 在此處插入 REST API App id
    • resourceAccess {id} -> REST API 的 OauthPermission id 值(您可以在 REST API 的清單中獲取它!)
    • Add registration for your client app
    • Edit Manifest of your client app - in the requiredResourceAccess section you must add information about REST API App:
      • resourceAppId -> insert REST API App id here
      • resourceAccess {id} -> OauthPermission id value of REST API (you can get it in REST API's manifest!)

      3) 在您的客戶端應用程序中

      3) In your client application

      • 使用 Autorest 生成您的 REST 客戶端(來自解決方案資源管理器:AddREST API 客戶端)或手動創建它
      • 添加 Microsoft.IdentityModel.Clients.ActiveDirectory nuget 包
      • 使用類似下面的代碼獲取并使用令牌來訪問您的 API:

      • generate your REST client using Autorest (from solution explorer: AddREST API client) or create it manually
      • add Microsoft.IdentityModel.Clients.ActiveDirectory nuget pack
      • get and use token to access your API with code similar to this:

          //request
          (..)
          var tokenCreds = getToken();
          ServiceClientCredentials credentials = tokenCreds;
      
          using (var client = new YourAPI(credentials)) {
          ...
          }
          (..)
      
          //getting token
      
      private static TokenCredentials getToken()
      {
          //get this from Federation Metadata Document in 
          //Azure Active Directory App registrations -> Endpoints
          var authority = "f1...";
      
          //Identifier of the target resource that is the recipient of the requested token
          var resource = "https://yourapi.azurewebsites.net";
      
          //client application id (see Azure Active Directory App registration
          //for your client app
          var clientId = "a71...";
      
          //return url - not relevant for Native apps (just has to be valid url)
          var redirectUri = "https://just-some-valid-url.net";
      
          AuthenticationContext authContext =
          new AuthenticationContext(string.Format
          ("https://login.windows.net/{0}",
      authority));
      
          AuthenticationResult tokenAuthResult =
          authContext.AcquireTokenAsync(resource,
          clientId,
          new Uri(redirectUri),
          new PlatformParameters(PromptBehavior.Auto)).Result;
      
          return new TokenCredentials(tokenAuthResult.AccessToken);
      }
      

    • 這篇關于如何使用 Azure Active Directory 授權的 Azure REST API 應用程序的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

      【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

ASP.NET Core authenticating with Azure Active Directory and persisting custom Claims across requests(ASP.NET Core 使用 Azure Active Directory 進行身份驗證并跨請求保留自定義聲明)
ASP.NET Core 2.0 Web API Azure Ad v2 Token Authorization not working(ASP.NET Core 2.0 Web API Azure Ad v2 令牌授權不起作用)
How do I get Azure AD OAuth2 Access Token and Refresh token for Daemon or Server to C# ASP.NET Web API(如何獲取守護進程或服務器到 C# ASP.NET Web API 的 Azure AD OAuth2 訪問令牌和刷新令牌) - IT屋-程序員軟件開發技
Azure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(異步調用時 Azure KeyVault Active Directory AcquireTokenAsync 超時)
Getting access token using email address and app password from oauth2/token(使用電子郵件地址和應用程序密碼從 oauth2/token 獲取訪問令牌)
New Azure AD application doesn#39;t work until updated through management portal(新的 Azure AD 應用程序在通過管理門戶更新之前無法運行)
主站蜘蛛池模板: 中式装修设计_室内中式装修_【云臻轩】中式设计机构 | 铝合金线槽_铝型材加工_空调挡水板厂家-江阴炜福金属制品有限公司 | 重庆磨床过滤机,重庆纸带过滤机,机床伸缩钣金,重庆机床钣金护罩-重庆达鸿兴精密机械制造有限公司 | 土壤墒情监测站_土壤墒情监测仪_土壤墒情监测系统_管式土壤墒情站-山东风途物联网 | IHDW_TOSOKU_NEMICON_EHDW系列电子手轮,HC1系列电子手轮-上海莆林电子设备有限公司 | 钢板仓,大型钢板仓,钢板库,大型钢板库,粉煤灰钢板仓,螺旋钢板仓,螺旋卷板仓,骨料钢板仓 | 合肥白癜风医院_合肥治疗白癜风医院_合肥看白癜风医院哪家好_合肥华研白癜风医院 | 设定时间记录电子秤-自动累计储存电子秤-昆山巨天仪器设备有限公司 | 企业微信营销_企业微信服务商_私域流量运营_艾客SCRM官网 | 恒温振荡混匀器-微孔板振荡器厂家-多管涡旋混匀器厂家-合肥艾本森(www.17world.net) | 钢木实验台-全钢实验台-化验室通风柜-实验室装修厂家-杭州博扬实验设备 | 冷库安装厂家_杭州冷库_保鲜库建设-浙江克冷制冷设备有限公司 | 杭州厂房降温,车间降温设备,车间通风降温,厂房降温方案,杭州嘉友实业爽风品牌 | 冷却塔改造厂家_不锈钢冷却塔_玻璃钢冷却塔改造维修-广东特菱节能空调设备有限公司 | 泰安办公家具-泰安派格办公用品有限公司 | 欧美日韩国产一区二区三区不_久久久久国产精品无码不卡_亚洲欧洲美洲无码精品AV_精品一区美女视频_日韩黄色性爱一级视频_日本五十路人妻斩_国产99视频免费精品是看4_亚洲中文字幕无码一二三四区_国产小萍萍挤奶喷奶水_亚洲另类精品无码在线一区 | 工业铝型材生产厂家_铝合金型材配件批发精加工定制厂商 - 上海岐易铝业 | 桂林腻子粉_内墙外墙抗裂砂浆腻子粉推荐广西鑫达涂料厂家供应 | 不干胶标签,不干胶标签纸_厂家-山东同力胶粘制品 | 焊接烟尘净化器__焊烟除尘设备_打磨工作台_喷漆废气治理设备 -催化燃烧设备 _天津路博蓝天环保科技有限公司 | 起好名字_取个好名字_好名网免费取好名在线打分 | 非甲烷总烃分析仪|环控百科 | 硫酸亚铁-聚合硫酸铁-除氟除磷剂-复合碳源-污水处理药剂厂家—长隆科技 | 青岛球场围网,青岛车间隔离网,青岛机器人围栏,青岛水源地围网,青岛围网,青岛隔离栅-青岛晟腾金属制品有限公司 | 亚克隆,RNAi干扰检测,miRNA定量检测-上海基屹生物科技有限公司 | 高光谱相机-近红外高光谱相机厂家-高光谱成像仪-SINESPEC 赛斯拜克 | 深圳公司注册-工商注册代理-注册公司流程和费用_护航财税 | 本安接线盒-本安电路用接线盒-本安分线盒-矿用电话接线盒-JHH生产厂家-宁波龙亿电子科技有限公司 | 青岛侦探调查_青岛侦探事务所_青岛调查事务所_青岛婚外情取证-青岛狄仁杰国际侦探公司 | 矿用履带式平板车|探水钻机|气动架柱式钻机|架柱式液压回转钻机|履带式钻机-启睿探水钻机厂家 | 代写标书-专业代做标书-商业计划书代写「深圳卓越创兴公司」 | 永嘉县奥阳陶瓷阀门有限公司| 家用净水器代理批发加盟_净水机招商代理_全屋净水器定制品牌_【劳伦斯官网】 | 家德利门业,家居安全门,别墅大门 - 安徽家德利门业有限公司 | 青海电动密集架_智能密集架_密集架价格-盛隆柜业青海档案密集架厂家 | 电动手术床,医用护理床,led手术无影灯-曲阜明辉医疗设备有限公司 | 青岛成人高考_山东成考报名网 | 比士亚-专业恒温恒湿酒窖,酒柜,雪茄柜的设计定制 | 粘度计维修,在线粘度计,二手博勒飞粘度计维修|收购-天津市祥睿科技有限公司 | 洗瓶机厂家-酒瓶玻璃瓶冲瓶机-瓶子烘干机-封口旋盖压盖打塞机_青州惠联灌装机械 | 废水处理-废气处理-工业废水处理-工业废气处理工程-深圳丰绿环保废气处理公司 |