Oauth 2.0 ADAL 4(实验性)在Windows桌面/本机和带有B2C的Windows Phone上表现不同
我想创建一个具有Azure AD B2C身份验证的Windows Phone 8.1应用程序。 作为基础,我使用了 桌面应用程序运行得很好。在我采用WP8.1的过程中,我遇到了第一个问题,我想在这里获得令牌: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
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
Convergence-v4
和Convergence-v4-RELEASE
分支中找到continueaQuireTokenAsync(args)
实现。据我所知,我需要使用v4以便能够通过B2C配置文件master
和dev
分支似乎不支持配置文件。假设我尝试将对continueaQuireTokenAsync
和AcquireTokenInteractiveHandler(验证器验证器、令牌缓存令牌缓存、IWebAuthenticationBrokerContinuationEventArgs参数)的支持添加到ADAL v4中,我无法成功,因为ContinuationData[]
将返回null
Kai,感谢您为社区发布示例。