Oauth 2.0 ADAL 4(实验性)在Windows桌面/本机和带有B2C的Windows Phone上表现不同

Oauth 2.0 ADAL 4(实验性)在Windows桌面/本机和带有B2C的Windows Phone上表现不同,oauth-2.0,windows-phone-8.1,adal,azure-ad-b2c,Oauth 2.0,Windows Phone 8.1,Adal,Azure Ad B2c,我想创建一个具有Azure AD B2C身份验证的Windows Phone 8.1应用程序。 作为基础,我使用了 桌面应用程序运行得很好。在我采用WP8.1的过程中,我遇到了第一个问题,我想在这里获得令牌: result = await authContext.AcquireTokenAsync(new string[] { Globals.clientId }, null, Globals.clientId, new Uri(Globals.redirectU

我想创建一个具有Azure AD B2C身份验证的Windows Phone 8.1应用程序。 作为基础,我使用了

桌面应用程序运行得很好。在我采用WP8.1的过程中,我遇到了第一个问题,我想在这里获得令牌:

result = await authContext.AcquireTokenAsync(new string[] { Globals.clientId },
                null, Globals.clientId, new Uri(Globals.redirectUri),
                platformParams, Globals.signInPolicy);
虽然我为桌面应用程序获得了一个漂亮而闪亮的令牌,但对于WP8.1应用程序(从WebAuthenticationBroker返回后),我只得到了一个…?code=。。。。。。答复

我不确定,但对我来说,WP8.1库的工作方式似乎是第一次调用到authorize,第二次调用到token端点

从那里接机时,我试图继续使用一个

var result = await authContext.AcquireTokenByAuthorizationCodeAsync(authCode, new Uri(Globals.redirectUri),
                credApp, new string[] { "" }, Globals.signInPolicy );
但是,无论我如何尝试传入ClientCredential或ClientAssertion,我最终都会收到一个普通的400错误请求(不会返回更多详细信息)


有人请告诉我哪里错了和/或给我指出正确的方向。

Windows Phone 8.1使用了一种延续模式,WAB将调用回拨应用程序。在上查看示例以演示流程,或者您可以直接查看

您需要在页面上实现IWebAuthenticationContinuable接口。 }

    #region IWebAuthenticationContinuable implementation

    // This method is automatically invoked when the application is reactivated after an authentication interaction through WebAuthenticationBroker.        
    public async void ContinueWebAuthentication(WebAuthenticationBrokerContinuationEventArgs args)
    {
        // pass the authentication interaction results to ADAL, which will conclude the token acquisition operation and invoke the callback specified in AcquireTokenAndContinue.
        await authContext.ContinueAcquireTokenAsync(args);
    }
    #endregion
------------------------------------------------------------------

更新

我创建了一个新的windows phone应用程序,并引用了ADAL v4。我检查了延续模型是否不适用于v4。它仅由ADAL v2使用。确保您正在使用adal-v4。 我仍然需要添加以下代码

 protected override void OnActivated(IActivatedEventArgs args)
    {

        if (args is IWebAuthenticationBrokerContinuationEventArgs)
        {
            Microsoft.Experimental.IdentityModel.Clients.ActiveDirectory.WebAuthenticationBrokerContinuationHelper.SetWebAuthenticationBrokerContinuationEventArgs(args as IWebAuthenticationBrokerContinuationEventArgs);
        }

        base.OnActivated(args);
    }

这将恢复令牌获取过程并返回访问令牌

我创建了一个完整的运行示例Windows Phone 8.1应用程序,该应用程序具有Azure AD B2C身份验证

调查结果(与ADAL v2 Azure AD验证相比):

  • 不需要ContinuationManager-ADAL v4中的
    SetWebAuthenticationBrokerContinuationEventArgs
    中介绍了这一点
  • 使用这种方法,代码在
    AcquireTokenAsync

谢谢。我意识到了这一点,我实现了延续,就像我在常规Azure广告中所做的那样。关键是,当从延续中返回时,AuthenticationResult与桌面应用程序不同。您是正确的,它以OIDC-ish方式工作。发生这种情况是因为桌面代码控制webview,并且能够在单个API调用(acquireToken)中兑换身份验证代码以获取访问令牌。对于windows phone,这是一种两步方法,因为WAB只需将身份验证代码返回给开发人员,但需要进一步处理才能获得实际的令牌,因此需要继续。但是一旦您从ContinueAcquireTokenAsync获得结果,它应该包含一个访问令牌,就像桌面调用一样。。。我将尝试进行更新。我无法在的
Convergence-v4
Convergence-v4-RELEASE
分支中找到
continueaQuireTokenAsync(args)
实现。据我所知,我需要使用v4以便能够通过B2C配置文件
master
dev
分支似乎不支持配置文件。假设我尝试将对
continueaQuireTokenAsync
AcquireTokenInteractiveHandler(验证器验证器、令牌缓存令牌缓存、IWebAuthenticationBrokerContinuationEventArgs参数)的支持添加到ADAL v4中,我无法成功,因为
ContinuationData[]
将返回
null
Kai,感谢您为社区发布示例。