【发布时间】:2019-02-28 15:37:29
【问题描述】:
我们正在尝试遵循 this 教程并在 Android 上运行客户端管理的身份验证。以下是我们在 Azure AD B2C 中配置应用程序的方式:
然后在 Azure 移动应用中,我们启用 Azure AD 身份验证:
其中Issuer Url 以v2.0/.well-known/openid-configuration 结尾,并包含取自 Azure 门户(目录 + 订阅菜单)的 B2C 租户 ID。
然后在 Xamarin 中我们有以下代码:
ADB2CClient = new PublicClientApplication(Constants.ClientID, // "48ab01cc-***********-73ef6c616da5"
Constants.Authority); // https://login.microsoftonline.com/tfp/{Tenant}/{Policy name}/oauth2/v2.0/authorize
ADB2CClient.RedirectUri = Constants.RedirectUri; // "msal{ClientID}://auth
authenticationResult = await ADB2CClient.AcquireTokenSilentAsync(
Constants.Scopes, // empty array
GetUserByPolicy(ADB2CClient.Users,
Constants.PolicySignUpSignIn), // Policy name from AD B2C
Constants.Authority, // https://login.microsoftonline.com/tfp/{Tenant}/{Policy name}/oauth2/v2.0/authorize
true);
var payload = new JObject();
if (authenticationResult != null && !string.IsNullOrWhiteSpace(authenticationResult.IdToken))
{
payload["access_token"] = authenticationResult.IdToken;
}
User = await TodoItemManager.DefaultManager.CurrentClient.LoginAsync(
MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory,
payload);
因此,我们能够从 AcquireTokenSilentAsync 方法获得有效的 JWT 令牌 (IdToken),但每次我们尝试运行 LoginAsync 时,我们都会得到 401 并带有以下堆栈跟踪:
{Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException: 您无权查看此目录或页面。
当我们尝试查看 Azure 应用服务日志时,它只是说
应用程序:2019-02-28T10:09:30 PID[7924] 信息发送响应:401.83 Unauthorized
没有任何额外的细节。
其余代码涵盖来自github的示例
【问题讨论】:
标签: c# azure xamarin azure-mobile-services azure-ad-b2c