亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Azure 活動目錄為 api 管理災難恢復拋出“未實現”

Azure 活動目錄為 api 管理災難恢復拋出“未實現”

C#
胡說叔叔 2022-11-22 10:18:35
我正在關注 Microsoft 文檔上的這個api 管理災難恢復指南,我已經設置了我的活動目錄用戶并從配置中獲取了值(按照建議),然后復制并粘貼了示例中的代碼var authenticationContext = new AuthenticationContext("https://login.microsoftonline.com/xxxx");var result = await authenticationContext.AcquireTokenAsync("https://management.azure.com/", "xxx", new Uri("https://resource.com"), new PlatformParameters());    似乎建議new PlatformParameters(PromptBehavior.Auto)不起作用,因為該對象不再需要您將參數傳遞給構造函數,我得到一個NotImplemented異常:System.NotImplementedException : The method or operation is not implemented.   at Microsoft.IdentityModel.Clients.ActiveDirectory.PlatformParameters.GetCoreUIParent()   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenInteractiveHandler.CreateWebUIOrNull(IPlatformParameters parameters)   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenInteractiveHandler..ctor(RequestData requestData, Uri redirectUri, IPlatformParameters platformParameters, UserIdentifier userId, String extraQueryParameters, String claims)   at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.AcquireTokenCommonAsync(String resource, String clientId, Uri redirectUri, IPlatformParameters parameters, UserIdentifier userId, String extraQueryParameters, String claims)   at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.AcquireTokenAsync(String resource, String clientId, Uri redirectUri, IPlatformParameters parameters)我覺得租戶的值,應用程序 ID 可能是錯誤的,所以我會盡我所能描述我從哪里獲得這些值:租戶編號:在 Azure Active Directory 選項上單擊“應用程序注冊”選項查找并單擊“端點”復制出 oauth 端點獲取 url 中的 guid 并將其粘貼到var authenticationContext = new AuthenticationContext("https://login.microsoftonline.com/{here}");申請編號在 Azure Active Directory 選項上單擊“應用程序注冊”選項查找并單擊具有所需權限的用戶點擊設置單擊列表中的“屬性”選項復制“應用程序 ID”粘貼它var result = await authenticationContext.AcquireTokenAsync("https://management.azure.com/", "{here}", new Uri("https://resource.com"), new PlatformParameters());
查看完整描述

1 回答

?
隔江千里

TA貢獻1906條經驗 獲得超10個贊

首先,您所引用的 Microsoft Docs 指南中的步驟向 Azure AD注冊一個Native應用程序,然后使用Delegated Permissions. 所以有代碼提示用戶登錄并輸入他們的憑據。


現在這段代碼可以與 .NET Framework(完整)控制臺應用程序完美配合,但不能與 .NET Core 配合使用。


static void Main(string[] args)

{

        var authenticationContext = new AuthenticationContext("https://login.microsoftonline.com/{tenant id}");

        var result = authenticationContext.AcquireTokenAsync("https://management.azure.com/", "{application id}", new Uri("{redirect uri}"), new PlatformParameters(PromptBehavior.Auto)).Result;

.NET Core 的根本問題是它不提供 UI 功能,因此 .NET Core 并不真正支持交互式流程。


這也是您必須從中刪除的原因PromptBehavior.Auto,new PlatformParameters(PromptBehavior.Auto)因為這會破壞 .NET Core。


您可以在下面提到的參考資料中找到更多信息:


這是 GitHub 上的一個線程,其代碼與您的代碼非常相似Interactive authentication in .net core 2.0 console application on windows

http://img1.sycdn.imooc.com//637c31a500018a2e06190118.jpg

GitHub 上的 ADAL 文檔。看清楚說Except for .NET Core, which does not provide any user interaction

http://img1.sycdn.imooc.com//637c31b00001b58b06210165.jpg

附帶一提,我知道.NET Core 3.0即將支持 Windows 桌面應用程序,但它仍處于預覽階段。

在未來,交互式流程應該與 .NET Core 3.0 和MSAL.NET(不同于ADAL.NET)一起工作。

此處有更多詳細信息:ADAL 不正確支持 .NET Core 3


http://img1.sycdn.imooc.com//637c31bc0001ce3106540186.jpg

查看完整回答
反對 回復 2022-11-22
  • 1 回答
  • 0 關注
  • 106 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號