【发布时间】:2017-01-19 07:47:49
【问题描述】:
我正在尝试创建一个需要有效用户的控制台应用程序的简单示例。该应用程序是一个简单的控制台应用程序:
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:登录的用户未分配给应用程序的角色
在 Azure 门户中,我已将 ConsoleApp1 注册为本机应用程序。
在必需的权限下,我勾选了:
- 登录并阅读用户资料
- 以登录用户身份访问目录
除此之外,我很困惑,错误消息告诉我需要为用户分配某种角色,但我在应用程序的设置中找不到任何位置。有人可以帮忙解释一下吗?
【问题讨论】:
标签: c# azure active-directory identity adal