Forum Cross Platform with Xamarin

Looking for working/good example of Azure MobileClient Services integrated with Azure B2C

I am looking for a good example of the todo list application or zumoapp or any app that shows how to use Azure MobileServices with Azure B2C Authentication/Authroization. I can get logged into my Azure b2c tenant but I can't get it to return an access_token that I can then use to pass into mobile services.

I setup the authicationclient in the app.xaml.cs file and then the app has the user navigate to settings and click a logon button to authenticate with AzureB2C. I can't seem to figure out how to get the access_token to return a value. I seem to be getting authenticated from Azure B2C but not getting the access_token.

I am wondering if it has to do with the scopes I am using when I call acquiretokeninteractive but I am having a hard time figuring out what that might be and look like.

A working example would be awesome.



                    public static IPublicClientApplication AuthenticationClient { get; private set; }
                    public static object UIParent { get; set; } = null;
                    public App()
                        AuthenticationClient = PublicClientApplicationBuilder.Create(Constants.ClientId)
                            //.WithRedirectUri($"msal{Constants.ClientId }://auth")
                        MainPage = new AppShell();


               async void OnLoginButtonClicked(object sender, EventArgs e)
                    AuthenticationResult result;
                    IEnumerable<IAccount> accounts;

                        System.Diagnostics.Debug.Write("before await get tokken");
                    result = await App.AuthenticationClient

                    .WithUseEmbeddedWebView(true) // this line was not in the sample, had to add to get to work on android without chrome installed

                JObject objToken = new JObject();
                objToken.Add("access_token", result.AccessToken);

                System.Diagnostics.Debug.WriteLine("access_token:", objToken.ToString());

// Access_token at this point is null, idToken has a value.

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

            accounts = await App.AuthenticationClient.GetAccountsAsync();
            //var account = GetUserData(result.AccessToken);
            //await Navigation.PushAsync(new LogoutPage(result));
        catch (MsalException ex)
            if (ex.Message != null && ex.Message.Contains("AADB2C90118"))
                //result = await OnForgotPassword();
                //await Navigation.PushAsync(new LogoutPage(result));
                else if (ex.ErrorCode != "authentication_canceled")
                        await DisplayAlert("An error has occurred", "Exception message: " + ex.Message, "Dismiss");


        public static class Constants
            // set to a unique value for your app, such as your bundle identifier. Used on iOS to share keychain access.
            static readonly string iosKeychainSecurityGroup = "com.xxxnextbook.mynextbook";
            public static string ApplicationURL = @"";
            static readonly string tenantName = "xxxNextBook";
            static readonly string tenantId = "";
            static readonly string clientId = "xxxxxxxx-72df-45e3-a84b-717317ec75c3";
            static readonly string policySignin = "B2C_1_xxxNextBookSignIn";
            static readonly string policyPassword = "B2C_1_xxxNextBookPasswordReset";

            // The following fields and properties should not need to be changed
            static readonly string[] scopes = { "" };
            static readonly string authorityBase = $"https://{tenantName}{tenantId}/";


  • XandManXandMan USMember ✭✭

    Have you had any luck getting this worked out?

    The Microsoft Docs page is lacking!

    Add authentication to your Xamarin Forms app

  • bradyguycbradyguyc Member ✭✭

    Thanks for the reference. No luck yet. I have read this article but haven't found the exact setting that is preventing the access token from being returned. I feel like it's got to be something in my tenant setup on the b2c side of things. I have a more complete description of the problem here:

    Hopefully the solution will materialize shortly..

Sign In or Register to comment.