2017-08-06 139 views
0

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

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); 

任何和所有的想法,赞赏。

+0

查看上面的代码更改: – sidsud

+0

查看上面的代码更改:objToken.Add(“authenticationToken”,result.IdToken);已更改为objToken.Add(“access_token”,result.IdToken),并且我已将MobileServiceAuthenticationProvider.MicrosoftAccount更改为MobileServiceAuthenticationProvider.WindowsAzzureActiveDirectory – sidsud

回答

0

我能解决这个问题。 Azure移动应用程序上的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); 

我可以提供关于天青AD配置的详细信息,如果任何人的爱好。所以现在,我有一个完全正常工作的Xamarin Forms Azure移动应用程序,它使用Azure AD B2C进行身份验证,并且迄今可与Microsoft,Google和Twitter提供商一起使用。

+0

我很感兴趣,如果您可以共享更多的细节,我们将不胜感激。我有XF与使用MVC /移动后端的Azure AD B2C身份验证一起工作;但是,从移动应用程序访问安全的表控制器时,我总是得到“未授权”。 –