Business Logic - Custom Endpoint: How can I get the username of the user making the request?

StackOverflow https://stackoverflow.com/questions/19749156

  •  03-07-2022
  •  | 
  •  

Question

I'm using Kinvey; specifically, a Business Logic Custom Endpoint.

In a business logic custom endpoint, it looks like the "request.username" property is ALWAYS the appkey, rather than the user actually sending the request.

How can I get the actual username of the requesting user (from the authorization header)?

Code:

function onRequest(request, response, modules){
  // Get username
  var username = request.username; 
}

In this code sample, "request.username" is always equal to the appkey, regardless of the authorization header in the true request.

The reason I need the true user is that I'm inserting a data row, and I need the "creator" value in the "_acl" column to be equal to the true user's "_id". Currently, it's always set to the appkey.

Was it helpful?

Solution

probably too late for you @RyanHenderson, but if someone else comes across this; the appropriate way to do this is to use the collectionAccess module:

var collectionAccess = modules.collectionAccess;
creatorId = collectionAccess.objectID(entity._acl.creator);
collectionAccess.collection('user').findOne({"_id" : creatorId}, function (err, userColl) {
   // ..do stuff with userColl
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top