gpt4 book ai didi

c# - native 应用程序和 Azure AD - Hello World

转载 作者:太空宇宙 更新时间:2023-11-03 23:04:44 24 4
gpt4 key购买 nike

我正在尝试创建一个需要有效用户的控制台应用程序的简单示例。该应用程序是一个简单的控制台应用程序:

static void Main(string[] args)
{
string authority = "https://login.windows.net/----------------.onmicrosoft.com";
AuthenticationContext context = new AuthenticationContext(authority);
Console.WriteLine("Context created");

string resource = "ConsoleApp1";
string clientId = "------------------------------------";
string redirectUri = "http://localhost";

var parameters = new PlatformParameters(PromptBehavior.RefreshSession);

context.TokenCache.Clear();


// Throws AggregateException--> AADSTS50105: The signed in user is not assigned to a role for the application
var token = Task.Run(() => context.AcquireTokenAsync(resource, clientId, new Uri(redirectUri), parameters)).Result;

Console.WriteLine("Hello, authorized user");
}

应用程序启动,显示登录窗口,然后抛出异常

AADSTS50105: The signed in user is not assigned to a role for the application

在 Azure 门户中,我已将 ConsoleApp1 注册为 native 应用程序。

所需权限下,我已选中:

  • 登录并阅读用户个人资料
  • 以登录用户身份访问目录

除此之外,我很困惑,错误消息告诉我,我需要为用户分配某种角色,但我在应用程序设置的任何地方都找不到它。有人可以帮忙解释一下吗?

最佳答案

您指定了不正确的资源(ConsoleApp1)。该资源应代表您已授予此应用程序并为其获取访问 token 的资源。

您似乎已向该应用程序授予 Azure AD Graph 的权限,您是否想要获取访问 token 以使用 Azure Graph REST?

如果我理解正确,您可以使用https://graph.windows.net替换资源。

更多关于与Azure AD集成的详细信息,您可以引用here .

关于c# - native 应用程序和 Azure AD - Hello World,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41736418/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com