我正在关注此tutorial以通过我的UWP中的AAD对我的用户进行身份验证。在门户网站中,我做了两个AD注册,一个Web应用程序' testservice'和一个本地应用程序&testnceicenative' testservicenative对testservice有权限。我已经在' testservice'中分配了。我希望他登录的用户。这是我在我的应用程序中编写的代码:
string clientId = "34324453-4354-4534-5454-4564565464";
string authority = "https://login.microsoftonline.com/testtenant.onmicrosoft.com";
string resourceUri = "http://testservice.azurewebsites.net";
string message;
while (user == null)
{
try
{
AuthenticationContext ac = new AuthenticationContext(authority);
PlatformParameters par = new PlatformParameters(PromptBehavior.Auto, false);
AuthenticationResult ar = await ac.AcquireTokenAsync(resourceUri, clientId, (Uri)null, par);
JObject payload = new JObject();
payload["access_token"] = ar.AccessToken;
user = await MobileService.LoginAsync(MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory, payload);
message = string.Format("You are now logged in - {0}", user.UserId);
}
catch (InvalidOperationException ex)
{
message = "You must log in. Login Required";
}
catch(Exception ex)
{
message = "You must log in. Login Required";
}
var dialog = new MessageDialog(message);
dialog.Commands.Add(new UICommand("OK"));
await dialog.ShowAsync();
}
我正在使用我的用户数据和authenticationtoke获取AuthenticationResult。但是当调用LoginAsync时会抛出一个 带有Message =&#34的InvalidOperationException;无法完成请求。 (未授权)"