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
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();