2

In my custom rest resource, I want to identify the user who made the API call. Since API call includes Authorization header with access token, can I get the user from this value?

2 Answers 2

5

Just use the UserInfo class, which:

Contains methods for obtaining information about the context user.

Specifically, you can get their Id, Name, Username, etc.

Id runningUserId = UserInfo.getUserId();
String runningUserName = UserInfo.getName();
String runningUserUsername = UserInfo.getUsername();
1
  • Thanks Andrian, I posted the question without trying it. My bad.
    – vishesh
    Jan 27, 2017 at 4:01
1

It works just like controllers.

UserInfo.getuserId() does the job

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .