Azure 活动目录为 api 管理灾难恢复抛出“未实现”

我正在关注 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());


胡说叔叔
浏览 68回答 1
1回答

隔江千里

首先,您所引用的 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 windowsGitHub 上的 ADAL 文档。看清楚说Except for .NET Core, which does not provide any user interaction附带一提,我知道.NET Core 3.0即将支持 Windows 桌面应用程序,但它仍处于预览阶段。在未来,交互式流程应该与 .NET Core 3.0 和MSAL.NET(不同于ADAL.NET)一起工作。此处有更多详细信息:ADAL 不正确支持 .NET Core 3
打开App,查看更多内容
随时随地看视频慕课网APP