none
[Node.js][Mobile Service] Easy Apis vs User id RRS feed

  • Question

  • My goal is to create an "Easy Api" that names blobs with uploaded data using user ids. I've tried to glue something together based on https://azure.microsoft.com/en-us/documentation/articles/mobile-services-how-to-use-server-scripts/, more precisely section "How to: Work with users and headers in a custom API". Unfortunately user object does not seem to ever exist on request object. I do realise that this tutorial is a little obsolete but I do not see anything more up to date on this subject.


    Tuesday, March 15, 2016 4:29 PM

Answers

  • Hi Andrew,

    The Mobile Services documentation is for the older style Mobile Services product. Easy Api is part of the newer Mobile Apps product. You can find some samples of what you're looking to do at https://github.com/Azure/azure-mobile-apps-node/tree/master/samples. Check out the authentication and custom-api-sql-stmt samples. Note that you need to set the custom API as authenticated (either through the portal or in code) for the request.azureMobile.user property to be populated.

    Hope this helps!

    Dale Anderson (Microsoft)

    • Marked as answer by AndrewA4 Wednesday, March 16, 2016 9:10 AM
    Tuesday, March 15, 2016 5:57 PM
  • The authenticated user object has moved to "reqeust.azureMobile.user" because the Easy Apis use the new application structure, which is expressjs + azure mobile apps node sdk

    You can leverage the following code snippet in Easy Apis:

    "get": function (req, res, next) {
            console.log("req: "+req.azureMobile.user.id);
            ...
        }
    You can refer to https://github.com/Azure/azure-mobile-apps-node/blob/master/e2etest/api/applicationPermission.js#L42 for the sample on Github.

    • Marked as answer by AndrewA4 Wednesday, March 16, 2016 9:10 AM
    Wednesday, March 16, 2016 2:06 AM
    Moderator

All replies

  • Hi Andrew,

    The Mobile Services documentation is for the older style Mobile Services product. Easy Api is part of the newer Mobile Apps product. You can find some samples of what you're looking to do at https://github.com/Azure/azure-mobile-apps-node/tree/master/samples. Check out the authentication and custom-api-sql-stmt samples. Note that you need to set the custom API as authenticated (either through the portal or in code) for the request.azureMobile.user property to be populated.

    Hope this helps!

    Dale Anderson (Microsoft)

    • Marked as answer by AndrewA4 Wednesday, March 16, 2016 9:10 AM
    Tuesday, March 15, 2016 5:57 PM
  • The authenticated user object has moved to "reqeust.azureMobile.user" because the Easy Apis use the new application structure, which is expressjs + azure mobile apps node sdk

    You can leverage the following code snippet in Easy Apis:

    "get": function (req, res, next) {
            console.log("req: "+req.azureMobile.user.id);
            ...
        }
    You can refer to https://github.com/Azure/azure-mobile-apps-node/blob/master/e2etest/api/applicationPermission.js#L42 for the sample on Github.

    • Marked as answer by AndrewA4 Wednesday, March 16, 2016 9:10 AM
    Wednesday, March 16, 2016 2:06 AM
    Moderator