WPF ADAL AcquireTokenAsync

时间:2016-07-19 14:51:07

标签: c# wpf office365 adal

我正在尝试使用ADAL(Active Directory身份验证库)在WPF应用中验证我的用户。

我正在使用以下代码:

AuthenticationContext context = new AuthenticationContext("https://login.windows.net/<my_tenant>.onmicrosoft.com");
AuthenticationResult result = await context.AcquireTokenAsync("https://graph.windows.net/", "<client_id>",new Uri("<redirect_uri>");

AcquireTokenAsync方法需要第三个参数:重定向uri。

我理解在Web应用程序中使用此参数。

但在WPF案例中,我并不了解设置/使用方法。

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

我们可以将其设置为localhost,以便authenticate端点可以将auth代码重定向到客户端。它将使用身份验证代码请求令牌。

以下是供您参考的示例:

AuthenticationContext context = new AuthenticationContext("https://login.microsoftonline.com/yourTenant/");
AuthenticationResult result = await context.AcquireTokenAsync("https://graph.windows.net/", "{clientId}", new Uri("http://localhost"), new PlatformParameters(PromptBehavior.Auto));