3

我想使用 Azure AD B2C 身份验证创建一个 Windows Phone 8.1 应用程序。作为基础,我使用了B2C Windows Desktop/Native Client 示例

桌面应用程序运行良好。在我的 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 库似乎在一种OIDC 模型中工作,其中第一次调用去授权,第二次调用到令牌端点。

从那里接我尝试继续使用收到的授权码

var result = await authContext.AcquireTokenByAuthorizationCodeAsync(authCode, new Uri(Globals.redirectUri),
                credApp, new string[] { "" }, Globals.signInPolicy );

但无论我如何尝试传递ClientCredentialClientAssertion我总是以一个普通的400 错误请求结束(没有返回更多详细信息)。

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

4

2 回答 2

2

Windows Phone 8.1 使用 WAB 调用调用应用程序的延续模型。在https://github.com/Azure-Samples/active-directory-dotnet-windowsphone-8.1/查看示例以演示流程,或者您可以直接查看https://github.com/Azure-Samples/active -directory-dotnet-windowsphone-8.1/blob/master/TodoListClient/MainPage.xaml.cs

您需要在页面上实现 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);
    }

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

于 2016-03-17T20:59:46.247 回答
1

我在这里使用 Azure AD B2C 身份验证创建了一个完整的运行示例 Windows Phone 8.1 应用程序...

结果(与 ADAL v2 Azure AD 身份验证相比):

  • 不需要 ContinuationManager - SetWebAuthenticationBrokerContinuationEventArgsADAL v4 对此进行了介绍
  • 使用这种方法,代码在之后直接继续执行AcquireTokenAsync
于 2016-03-30T18:12:34.990 回答