Azure AD B2C Azure移动服务Xamrin表单示例

时间:2017-08-06 20:06:15

标签: azure xamarin.forms azure-ad-b2c

寻找通过Azure AD B2C进行身份验证的Xamarin Forms开发的Azure移动服务示例。我有一个可行的解决方案,我可以在Xamarin Forms中使用Azure B2C进行身份验证,但无法在Azure移动服务中使用生成的令牌。请参阅下面的代码段:

public static PublicClientApplication AuthenticationClient { get; private set; }
public static MobileServiceClient MobileService = new MobileServiceClient(Constants.MobileServiceClientName);                  
result = App.AuthenticationClient.AcquireTokenAsync(
                        Constants.Scopes,
                        string.Empty,
                        UIBehavior.SelectAccount,
                        string.Empty,
                        null,
                        Constants.Authority, null);
                    JObject objToken = new JObject();
objToken.Add("authenticationToken", result.IdToken);

//I am successfully able to get an Id token for Microsoft, Google and Twitter providers but when I use the token to login to my Azure Mobile Service app, I get a "Not Authorized" error

MobileServiceUser user = await MobileService.LoginAsync(MobileServiceAuthenticationProvider.MicrosoftAccount, objToken);

赞赏任何和所有想法。

1 个答案:

答案 0 :(得分:0)

我能够解决这个问题。我的Azure Mobile App上的Azure AD Provider配置未正确配置。

以下是更正后的代码:

public static PublicClientApplication AuthenticationClient { get; private set; }
public static MobileServiceClient MobileService = new MobileServiceClient(Constants.MobileServiceClientName);                  
result = App.AuthenticationClient.AcquireTokenAsync(
                        Constants.Scopes,
                        string.Empty,
                        UIBehavior.SelectAccount,
                        string.Empty,
                        null,
                        Constants.Authority, null);
                    JObject objToken = new JObject();
objToken.Add("access_token", result.IdToken);

//I am successfully able to get an Id token for Microsoft, Google and Twitter providers but when I use the token to login to my Azure Mobile Service app, I get a "Not Authorized" error

MobileServiceUser user = await MobileService.LoginAsync(MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory, objToken);

如果有兴趣,我可以提供有关Azure AD配置的更多详细信息。所以现在,我有一个完全工作的Xamarin Forms Azure移动应用程序,使用Azure AD B2C进行身份验证,到目前为止,它与Microsoft,Google和Twitter提供商合作。