2017-08-06 4 views
0

Suchen Sie nach einem Beispiel für Azure Mobile Services, das in Xamarin Forms entwickelt wurde und über Azure AD B2C authentifiziert wird. Ich habe eine funktionierende Lösung, mit der ich Azure B2C in Xamarin-Formularen authentifizieren kann, aber das resultierende Token in Azure Mobile Services nicht verwenden kann. Siehe Code-Schnipsel unten:Azure AD B2C Azure Mobile Dienste Xamrin Forms Beispiel

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

Alle und alle Ideen werden geschätzt.

+0

Siehe Codeänderungen zu dem oben genannten: – sidsud

+0

Siehe Codeänderungen zu obigem: objToken.Add ("authenticationToken", result.IdToken); wurde in objToken.Add ("access_token", result.IdToken) geändert und ich habe MobileServiceAuthenticationProvider.MicrosoftAccount in MobileServiceAuthenticationProvider.WindowsAzzureActiveDirectory geändert. – sidsud

Antwort

0

Ich konnte das Problem lösen. Die Konfiguration des Azure AD-Providers in meiner Azure Mobile App wurde nicht ordnungsgemäß konfiguriert. Hier

ist der korrigierte Code:

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

ich mehr Details über die Azure AD-Konfiguration zur Verfügung stellen kann, wenn jemand interessiert ist. Jetzt habe ich eine voll funktionsfähige Xamarin Forms Azure Mobile App, die mit Azure AD B2C authentifiziert wurde und bisher mit Microsoft-, Google- und Twitter-Anbietern funktioniert.

+0

Ich bin interessiert, wenn Sie mehr Details teilen könnten, die geschätzt werden. Ich habe XF mit Azure AD B2C Authentifizierung mit MVC/Mobile Backend arbeiten; Ich erhalte jedoch immer "Nicht autorisiert", wenn ich über die mobile App auf einen sicheren Table Controller zugreife. –