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


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();
  • Thanks Andrian, I posted the question without trying it. My bad.
    – vishesh
    Commented Jan 27, 2017 at 4:01

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 .