【发布时间】:2016-05-24 20:28:34
【问题描述】:
在示例here 的基础上,我尝试在客户端验证 MSA 登录,并让它在服务端进行验证。与我的不同之处在于我在 Windows 10 中使用新的 WebAccount 相关 API,而不是现在已弃用的 Live SDK。
到目前为止,我得到了:
var provider = await WebAuthenticationCoreManager.FindAccountProviderAsync("https://login.microsoft.com", "consumers");
var request = new WebTokenRequest(provider, "service::wl.basic wl.emails::DELEGATION", "none");
var result = await WebAuthenticationCoreManager.RequestTokenAsync(request);
if (result.ResponseStatus == WebTokenRequestStatus.Success)
{
string token = result.ResponseData[0].Token;
//This calls my custom wrappers around the Live REST API v5 and runs successfully with this token
var acc = await LiveApi.GetLiveAccount(token);
var jtoken = new JObject
{
{"authenticationToken", token}
};
try
{
//Shouldn't this work? but raises a 401
await App.MobileService.LoginAsync(MobileServiceAuthenticationProvider.MicrosoftAccount, jtoken);
//Alternate method? Also raises a 401
//await App.MobileService.LoginWithMicrosoftAccountAsync(token);
}
}
正如我在 cmets 中提到的,我得到的只是 401。
据我所知,该应用程序已在 Microsoft 帐户开发中心正确配置:
- 我在 Azure 门户中使用同一应用程序中的客户端 ID 和密码。
- JWT 发行不受限制。
- 重定向 URL 的格式为
https://{appname}.azurewebsites.net/.auth/login/microsoftaccount/callback
当我切换到使用纯服务器端身份验证时,身份验证工作正常。即
await App.MobileService.LoginAsync(MobileServiceAuthenticationProvider.MicrosoftAccount);
有什么想法吗?我错过了什么吗?任何帮助将不胜感激。
更新: 我在 WebTokenRequestResult 中返回的令牌长度为 877 个字符,并且似乎不是 JWT 格式,带有点 (.) 分隔符,我很确定这是问题所在。当客户端调用上面的代码时,登录服务会出现以下错误:
JWT validation failed: IDX10708: 'System.IdentityModel.Tokens.JwtSecurityTokenHandler' cannot read this string: 'EwCQAq1DBAAUGCCXc8wU/zFu9QnLdZXy+...Zz9TbuxCowNxsEPPOvXwE='.
Application: The string needs to be in compact JSON format, which is of the form: '<Base64UrlEncodedHeader>.<Base64UrlEndcodedPayload>.<OPTIONAL, Base64UrlEncodedSignature>'..
Application: 2015-12-07T17:47:09 PID[5740] Information Sending response: 401.71 Unauthorized
令牌目前是什么格式?可以转成 JWT 吗?
仍然没有更接近解决方案,因此感谢您的帮助。
【问题讨论】:
标签: c# azure authentication azure-mobile-services uwp