Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
试图通过Azure AD登录用户在UWP中失败_Azure_Win Universal App_Uwp - Fatal编程技术网

试图通过Azure AD登录用户在UWP中失败

试图通过Azure AD登录用户在UWP中失败,azure,win-universal-app,uwp,Azure,Win Universal App,Uwp,我遵循这一点,通过我的UWP中的AAD对我的用户进行身份验证。在门户中,我注册了两个广告,一个是web应用程序“testservice”,另一个是本地应用程序“testservicenative”,其中testservicenative拥有testservice的权限。我还在“testservice”中指定了我希望他登录的用户。以下是我在应用程序中编写的代码: string clientId = "34324453-4354-4534-5454-4564565464";

我遵循这一点,通过我的UWP中的AAD对我的用户进行身份验证。在门户中,我注册了两个广告,一个是web应用程序“testservice”,另一个是本地应用程序“testservicenative”,其中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();
            }
我正在使用我的用户数据和AuthenticationTok获取AuthenticationResult。然而,当调用LoginAsync时,它抛出一个 InvalidOperationException,消息为=“请求无法完成。(未经授权)”

  • 我编写的过程和代码是否正确(示例适用于Windows 8应用商店应用)
  • 有什么问题吗

  • 我认为问题在于传递给
    AcquireTokenAsync
    方法的
    (Uri)null
    。通常,您需要在Azure AD中注册应用程序的回调Uri。然后,您必须在此处将相同的Uri传递给此方法。通过调用
    Windows.Security.Authentication.Web.WebAuthenticationBroker.GetCurrentApplicationCallbackUri()
    可以找到正确的CallbackUri。我认为问题在于传递给
    AcquireTokenAsync
    方法的
    (Uri)null
    。通常,您需要在Azure AD中注册应用程序的回调Uri。然后,您必须在此处将相同的Uri传递给此方法。通过调用
    Windows.Security.Authentication.Web.WebAuthenticationBroker.GetCurrentApplicationCallbackUri()