1

I've been using Azure Mobile Services and now I created one of the new Mobile Apps via the all new Azure Portal.

While using Mobile Services it was possible to limit API access via an application key. The concept of this key no longer applies to Mobile Apps it seems.

All I need is a really lightweight protection of my services, exactly what the Application Key did. I just want to prevent that everybody out there navigates to my Azure app and messes around with my database; the App Key was perfect for those cases when you did not have anything to hide but wanted to prevent "spamming".

I see there is now Active Directory integration as an alternative but unfortunately I cannot find a guide how to move from App Key to something else.

Krumelur
  • 32,180
  • 27
  • 124
  • 263
  • Application key problem is solved on Azure Mobile Services [here]. [here]: http://stackoverflow.com/a/40006470/5703260 – thisisfatih Oct 25 '16 at 12:46

1 Answers1

0

Check this post How to configure your App Service application to use Azure Active Directory login

this authentication sample code works with UWP

private async Task AuthenticateAsync()
        {
            while (user == null)
            {
                string message=string.Empty;

            var provider = "AAD";

            PasswordVault vault=new PasswordVault();
            PasswordCredential credential = null;

            try
            {
                credential = vault.FindAllByResource(provider).FirstOrDefault();
            }
            catch (Exception)
            {
                //Ignore exception
            }
            if (credential != null)
            {
                // Create user
                user = new MobileServiceUser(credential.UserName);
                credential.RetrievePassword();
                user.MobileServiceAuthenticationToken = credential.Password;

                // Add user
                App.MobileServiceClient.CurrentUser = user;

                try
                {
                    //intentamos obtener un elemento para determinar si nuestro cache ha experidado
                    await App.MobileServiceClient.GetTable<Person>().Take(1).ToListAsync();
                }
                catch (MobileServiceInvalidOperationException ex)
                {
                    if (ex.Response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
                    {
                        //remove expired token
                        vault.Remove(credential);
                        credential = null;
                        continue;
                    }
                }
            }
            else
            {
                try
                {
                    //Login
                    user = await App.MobileServiceClient
                        .LoginAsync(provider);

                    //Create and store credentials
                    credential = new PasswordCredential(provider,
                        user.UserId, user.MobileServiceAuthenticationToken);
                    vault.Add(credential);
                }
                catch (MobileServiceInvalidOperationException ex)
                {
                    message = "You must log in. Login Required";
                }
            }
            message = string.Format("You are now logged in - {0}", user.UserId);
            var dialog = new MessageDialog(message);
            dialog.Commands.Add(new UICommand("OK"));
            await dialog.ShowAsync();

        }
    }