【发布时间】:2017-06-11 17:43:23
【问题描述】:
我正在创建一个使用 Azure B2C 对用户进行身份验证的 Xamarin.Forms PCL 应用程序。我之前使用的是 Microsoft.Identity.Client 版本 1.0.304142221-alpha,但在 NuGet 上发布后我刚刚更新到 1.1.0-preview。
我还使用 Azure MobileServiceClient 登录用户,因此只有经过身份验证的用户才能调用我的表。
我能够成功进行身份验证,我设置为 this sample on GitHub.
使用以前版本的Microsoft.Identity.Client,我可以像这样登录MobileServiceClient:
AuthenticationResult ar = await App.AuthenticationClient.AcquireTokenAsync(Config.Scopes,
string.Empty, UiOptions.SelectAccount, string.Empty, null,
Config.Authority, Config.SignUpSignInpolicy);
JObject payload = getPayload(ar.IdToken);
payload["access_token"] = ar.Token;
string objectId = payload["oid"].ToString();
MobileServiceUser u = await App.MobileService.LoginAsync(MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory,
payload);
但是,更新后,AuthenticationResult 不再有名为Token 的成员。相反,它有AccessToken,对我来说,它总是返回null。
我尝试使用IdToken 登录MobileServiceClient,但这会产生未经授权的错误。
我认为这个问题可能与我定义的范围有关。现在我有:
public static string[] Scopes = { "https://<MyTennant>/<MyAPIName>.read"};
我是否缺少任何范围来获取AccessToken 或者是其他地方的问题?
更新:这是我在 Azure 门户中的设置 对于我的 API:
在我的应用程序中,我是这样登录的:
AuthenticationResult ar = await App.AuthenticationClient.AcquireTokenAsync(Scopes,
GetUserByPolicy(App.AuthenticationClient.Users, PolicySignUpSignIn),
App.UiParent);
payload = getPayload(ar.IdToken);
payload["access_token"] = ar.IdToken;
var mobileService = new Microsoft.WindowsAzure.MobileServices.MobileServiceClient("https://giftthis.azurewebsites.net/.auth/");
MobileServiceUser u = await mobileService.LoginAsync(MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory, payload);
LoginAsync 现在正在执行,但它返回 null,所以我仍然无法调用表。
【问题讨论】:
标签: xamarin xamarin.forms azure-active-directory azure-ad-b2c msal