Allowing Multiple Routes in Custom API for Azure Mobile Service

I am working on Azure Mobile Service where I created a custom api. You can set permissions for them (for example, public, application, user and admin), which is very useful. But I need a multi-level api (for example /api/user/profile/{userId}

) and be able to set some permissions on a sub-api sub-level.

I found that it is possible to add other levels of api paths with the following code

exports.register = function (api) {

    /* Get public user profile on some other user */
    api.get('/profile/:userId', getProfileFunc);

    /* Get private profile only for the authenticated user */
    api.get('/profile', getProvateProfileFunc);

    /* Update provate profile only for the authenticated user */
    api.put('/profile', updateProfileFunc);
}

exports.get = getUserListFunc;

      

The api permissions are set via the {api-name} .json file for the top level. But how can I set permission in api sub-level that is different from parent api? Illustration:
GET: api / user gets a list of users and this application for permission
GET: api / user / profile gets a profile for a (authenticated) user and therefore needs user permission.

And the permissions in user.json are

{
  "routes": {
    "*": {
      "get": {"permission": "application"},
      "post": {"permission": "admin"},
      "put": {"permission": "admin"},
      "patch": {"permission": "admin"},
      "delete": {"permission": "admin"}
    }
  }
}

      

I am working with a git repository connected to my WAMS.

+3


source to share


1 answer


Json file supports routes. Try the following:



{
    "routes": {          
        "/" : { "permission": "public" },
        "/user/profile/:userId" : {
            "get": { "permission": "public" },
            "post": { "permission": "authenticated" }
        }
    }
}

      

+2


source







All Articles