2017-08-06 11 views
0

Azure AD B2Cで認証されたXamarinフォームで開発されたAzure Mobile Servicesの例をお探しください。私はXamarin FormsでAzure B2Cを使用して認証でき、Azure Mobile Servicesで結果のトークンを使用することができない実用的なソリューションを持っています。以下のコードスニペットをご覧ください: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 Mobile AppのAzure ADプロバイダ設定が正しく設定されていませんでした。誰もが興味を持っている場合、私はアズールADの設定についての詳細を提供することができます

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 B2Cを使って認証されたXamarin Forms Azure Mobile Appがあり、これまでMicrosoft、Google、Twitterプロバイダと連携しています。

+0

私は興味があります。私はXFがAzure AD B2C認証をMVC /モバイルバックエンドで完璧に扱っています。ただし、モバイルアプリから保護されたテーブルコントローラにアクセスする際は、常に「Not Authorized」と表示されます。 –