2017-08-06 59 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身份驗證一起工作;但是,從移動應用程序訪問安全的表控制器時,我總是得到「未授權」。 –