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

如何使用 Azure Active Directory 授權(quán)的 Azure REST API 應(yīng)

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

問題描述

限時送ChatGPT賬號..

我已將 API 應(yīng)用程序 部署到 Azure,但如果身份驗(yàn)證(使用 AAD)設(shè)置為 ON,我在創(chuàng)建 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.

當(dāng)我嘗試生成服務(wù)客戶端時(當(dāng)身份驗(yàn)證關(guān)閉時),然后生成客戶端代碼(使用 Autorest 完成)并且代碼正在工作,但是當(dāng)我打開身份驗(yàn)證時(以及請求未通過身份驗(yàn)證時采取的操作是設(shè)置為 使用 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) 服務(wù)調(diào)用返回401 Unauthorized(沒有重定向到AAD登錄頁面)

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

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

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")

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

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/

也按照此視頻工作,并且此視頻中顯示的所有內(nèi)容都正常工作,除了 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 客戶端使用),那么它會返回有效結(jié)果2) 我發(fā)現(xiàn)我正在使用沒有憑據(jù)的 REST API(我認(rèn)為在這種情況下應(yīng)該顯示 Azure AD 登錄屏幕......但事實(shí)并非如此)

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

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

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:客戶端應(yīng)用程序已請求訪問資源https....azurewebsites.net".此請求失敗,因?yàn)榭蛻舳宋丛谄?requiredResourceAccess 列表中指定此資源.跟蹤 ID:4176e...相關(guān) ID:1d612d...時間戳:2016-11-13 18:28:34Z

這些是我已經(jīng)完成的步驟:

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

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

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

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

1) registered my client app in Azure Active Directory

2) 從客戶端應(yīng)用程序調(diào)用 REST API 時,我正在添加 ServiceClientCredentials

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

3) 在創(chuàng)建 ServiceClientCredentials 時,我提供了 4 個元素-authority = 這是來自 AAD 應(yīng)用注冊 -> 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(=>作為請求令牌接收者的目標(biāo)資源的標(biāo)識符)

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

-clientId => 這是我在 AAD 中注冊客戶端應(yīng)用程序后獲得的應(yīng)用程序 ID-redirect Uri => 因?yàn)槲业目蛻舳藨?yīng)用程序是本機(jī)應(yīng)用程序,所以這只是任何有效的 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

如何在我的客戶端應(yīng)用程序中指定此資源?

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

推薦答案

我設(shè)法找到了有關(guān)如何啟用對 Azure REST API 應(yīng)用程序的 AAD 授權(quán)的解決方案.以防萬一有人遇到同樣的挑戰(zhàn),我希望這會有所幫助.

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.

這些是我執(zhí)行的步驟:

1) 在應(yīng)用服務(wù)中 -> 認(rèn)證/授權(quán)

1) In App services -> Authentication/authorization

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

2) 在 Azure Active Directory -> 應(yīng)用注冊

2) In Azure Active Directory -> App registrations

  • 為您的客戶端應(yīng)用添加注冊
  • 編輯客戶端應(yīng)用程序的清單 - 在 requiredResourceAccess 部分中,您必須添加有關(guān) REST API 應(yīng)用程序的信息:
    • 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) 在您的客戶端應(yīng)用程序中

      3) In your client application

      • 使用 Autorest 生成您的 REST 客戶端(來自解決方案資源管理器:AddREST API 客戶端)或手動創(chuàng)建它
      • 添加 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);
      }
      

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

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

相關(guān)文檔推薦

ASP.NET Core authenticating with Azure Active Directory and persisting custom Claims across requests(ASP.NET Core 使用 Azure Active Directory 進(jìn)行身份驗(yàn)證并跨請求保留自定義聲明)
ASP.NET Core 2.0 Web API Azure Ad v2 Token Authorization not working(ASP.NET Core 2.0 Web API Azure Ad v2 令牌授權(quán)不起作用)
How do I get Azure AD OAuth2 Access Token and Refresh token for Daemon or Server to C# ASP.NET Web API(如何獲取守護(hù)進(jìn)程或服務(wù)器到 C# ASP.NET Web API 的 Azure AD OAuth2 訪問令牌和刷新令牌) - IT屋-程序員軟件開發(fā)技
Azure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(異步調(diào)用時 Azure KeyVault Active Directory AcquireTokenAsync 超時)
Getting access token using email address and app password from oauth2/token(使用電子郵件地址和應(yīng)用程序密碼從 oauth2/token 獲取訪問令牌)
New Azure AD application doesn#39;t work until updated through management portal(新的 Azure AD 應(yīng)用程序在通過管理門戶更新之前無法運(yùn)行)
主站蜘蛛池模板: 福建成考网-福建成人高考网| 网站建设,北京网站建设,北京网站建设公司,网站系统开发,北京网站制作公司,响应式网站,做网站公司,海淀做网站,朝阳做网站,昌平做网站,建站公司 | 南京和瑞包装有限公司 | 【甲方装饰】合肥工装公司-合肥装修设计公司,专业从事安徽办公室、店面、售楼部、餐饮店、厂房装修设计服务 | 电动高尔夫球车|电动观光车|电动巡逻车|电动越野车厂家-绿友机械集团股份有限公司 | 上海恒驭仪器有限公司-实验室平板硫化机-小型平板硫化机-全自动平板硫化机 | 破碎机_上海破碎机_破碎机设备_破碎机厂家-上海山卓重工机械有限公司 | 中控室大屏幕-上海亿基自动化控制系统工程有限公司 | 镀锌方管,无缝方管,伸缩套管,方矩管_山东重鑫致胜金属制品有限公司 | 紫外荧光硫分析仪-硫含量分析仪-红外光度测定仪-泰州美旭仪器 | U拓留学雅思一站式服务中心_留学申请_雅思托福培训 | 400电话_400电话申请_888元包年_400电话办理服务中心_400VIP网 | 臭氧灭菌箱-油桶加热箱-原料桶加热融化烘箱-南京腾阳干燥设备厂 臭氧发生器_臭氧消毒机 - 【同林品牌 实力厂家】 | 灌木树苗-绿化苗木-常绿乔木-价格/批发/基地 - 四川成都途美园林 | 膜结构_ETFE膜结构_膜结构厂家_膜结构设计-深圳市烨兴智能空间技术有限公司 | 钢托盘,铁托盘,钢制托盘,镀锌托盘,饲料托盘,钢托盘制造商-南京飞天金属13260753852 | 早报网| 陕西华春网络科技股份有限公司| 防爆正压柜厂家_防爆配电箱_防爆控制箱_防爆空调_-盛通防爆 | 拖链电缆_柔性电缆_伺服电缆_坦克链电缆-深圳市顺电工业电缆有限公司 | 专业的新乡振动筛厂家-振动筛品质保障-环保振动筛价格—新乡市德科筛分机械有限公司 | 反渗透水处理设备|工业零排放|水厂设备|软化水设备|海南净水设备--海南水处理设备厂家 | 珠海冷却塔降噪维修_冷却塔改造报价_凉水塔风机维修厂家- 广东康明节能空调有限公司 | 书信之家_书信标准模板范文大全| 中高频感应加热设备|高频淬火设备|超音频感应加热电源|不锈钢管光亮退火机|真空管烤消设备 - 郑州蓝硕工业炉设备有限公司 | 冷镦机-多工位冷镦机-高速冷镦机厂家-温州金诺机械设备制造有限公司 | 细沙回收机-尾矿干排脱水筛设备-泥石分离机-建筑垃圾分拣机厂家-青州冠诚重工机械有限公司 | 基本型顶空进样器-全自动热脱附解吸仪价格-AutoHS全模式-成都科林分析技术有限公司 | 污水提升器,污水提升泵,地下室排水,增压泵,雨水泵,智能供排水控制器-上海智流泵业有限公司 | 英国雷迪地下管线探测仪-雷迪RD8100管线仪-多功能数字听漏仪-北京迪瑞进创科技有限公司 | 盐水蒸发器,水洗盐设备,冷凝结晶切片机,转鼓切片机,絮凝剂加药系统-无锡瑞司恩机械有限公司 | 北京翻译公司_同传翻译_字幕翻译_合同翻译_英语陪同翻译_影视翻译_翻译盖章-译铭信息 | 四川实木门_成都实木门 - 蓬溪聚成门业有限公司 | 座椅式升降机_无障碍升降平台_残疾人升降平台-南京明顺机械设备有限公司 | 精密模具-双色注塑模具加工-深圳铭洋宇通 | 定硫仪,量热仪,工业分析仪,马弗炉,煤炭化验设备厂家,煤质化验仪器,焦炭化验设备鹤壁大德煤质工业分析仪,氟氯测定仪 | 自清洗过滤器,浅层砂过滤器,叠片过滤器厂家-新乡市宇清净化 | 青岛侦探_青岛侦探事务所_青岛劝退小三_青岛调查出轨取证公司_青岛婚外情取证-青岛探真调查事务所 | 干培两用箱-细菌恒温培养箱-菲斯福仪器 | 防爆正压柜厂家_防爆配电箱_防爆控制箱_防爆空调_-盛通防爆 | 真空泵厂家_真空泵机组_水环泵_旋片泵_罗茨泵_耐腐蚀防爆_中德制泵 |