Setup Mobile Service table permissions and authentication

Azure Mobile Services is deprecated, please migrate to Azure App Service.

Tutorial requirements:

This article builds on top of the previous tutorial where an Android Todo app was created with Azure Mobile Services. However most steps can be adapted for any Mobile Services Android app.

  1. Edit TodoItem table insert permissions to Only Authenticated Users.
  2. Create twitter app.

    Copy _Mobile Service URL* from Azure Mobile Service Dashboard

    Paste the Azure _Mobile Service URL* into Twitter app’s Website and Callback URL fields and save. Then in Settings tab tick the ‘Allow this application to be used Sign in with Twitter’ checkbox.

  3. In Twitter app’s API Keys tab copy the API key & API secret.

    And paste them into Identity > Twitter settings.

  4. In Android Studio ToDoActivity cut the code block under the new Mobile Service client.

    And paste into a new method _createTable()*.

  5. Replace the code block with a new authenticate() method.
    private void authenticate() {
      mClient.login(MobileServiceAuthenticationProvider.Twitter, new UserAuthenticationCallback() {
        public void onCompleted(MobileServiceUser mobileServiceUser, Exception e, ServiceFilterResponse serviceFilterResponse) {
          if (e==null)
            createAndShowDialog(String.format("You are signed in as %s"), mobileServiceUser.getUserId() );

    Then build and run

  6. Sign-in with Twitter.
  7. You can record the userId on the server-side. Edit table Script > Insert
    function insert(item, user, request) {
      item.userId = user.userId;

  8. Add another Todo item in the app.
    Refresh the ToDoItem table to see the new item with userId.
  9. Now change Script > Read so app shows only the authenticated user’s items.

     function read(query, user, request) {
       query.where({ userId: user.userId });
  10. Refresh app to see changes.
    The list should only show ToDo items that belong to that user now.

Impressive - with just a couple of lines of code the app is updated to enable user authentication and handle identity requests.

Azure Mobile Services also allows you to send Push Notifications which is covered in the next tutorial.