17

I am trying to find a way to get the information about the salesforce enterprise user from his auth_token. I want to find the username, email address and role(admin/user) from the auth-token.

Something on the lines of

curl -XGET 'https://na1.salesforce.com/Userinfo' -H "Authorization: Bearter token"

which would give me the required information

I have been looking at the REST API and MetaData API but did not find anything. Preferably I would want this information from a REST API and not some programmatic API. Any help?

  • Can anyone shoot me a example of how to build this GET request and pass that Identity Id into it? Thanks! – Christian Jan 5 '16 at 19:54
22

Assuming you've done OAuth, the OAuth response includes an id field with an Identity Service URL - e.g.:

{
    "id":"https://login.salesforce.com/id/00D50000000IZ3ZEAW/00550000001fg5OAAQ",
    "issued_at":"1296458209517",
    "refresh_token":"5Ae...",
    "instance_url":"https://na1.salesforce.com",
    "signature":"0/1...",
    "access_token":"00D..."
}

GET this URL, passing the access token, and you'll receive the user info. Note the use of -L to follow redirects:

$ curl -L -H 'X-PrettyPrint: 1' -H 'Authorization: Bearer 00D...' https://login.salesforce.com/id/00D50000000IZ3ZEAW/00550000001fg5OAAQ
{
    "id":"https://login.salesforce.com/id/00D50000000IZ3ZEAW/00550000001fg5OAAQ",
    "asserted_user":true,
    "user_id":"00550000001fg5OAAQ",
    "organization_id":"00D50000000IZ3ZEAW",
    "username":"user@example.com",
    "nick_name":"user1.2950476911907334E12",
    "display_name":"Sample User",
    "email":"user@example.com",
    "status":{
        "created_date":"2010-11-08T20:55:33.000+0000",
        "body":"Working on OAuth 2.0 article"
    },
    "photos":{
        "picture":"https://c.na1.content.force.com/profilephoto/005/F",
        "thumbnail":"https://c.na1.content.force.com/profilephoto/005/T"
    },
    "urls":{
        "enterprise":"https://na1.salesforce.com/services/Soap/c/{version}/00D50000000IZ3Z",
        "metadata":"https://na1.salesforce.com/services/Soap/m/{version}/00D50000000IZ3Z",
        "partner":"https://na1.salesforce.com/services/Soap/u/{version}/00D50000000IZ3Z",
        "rest":"https://na1.salesforce.com/services/data/v{version}/",
        "sobjects":"https://na1.salesforce.com/services/data/v{version}/sobjects/",
        "search":"https://na1.salesforce.com/services/data/v{version}/search/",
        "query":"https://na1.salesforce.com/services/data/v{version}/query/",
        "recent":"https://na1.salesforce.com/services/data/v{version}/recent/",
        "profile":"https://na1.salesforce.com/00550000001fg5OAAQ"
    },
    "active":true,
    "user_type":"STANDARD",
    "language":"en_US",
    "locale":"en_US",
    "utcOffset":-28800000,
    "last_modified_date":"2011-01-14T23:28:01.000+0000"
}

More info on the Identity Service.

  • is there now a way to to fetch this identity information for all the users of the enterprise using the admin's auth token? This is required since I do not know the ids of all users to fetch their information. Is there a way to do it via some call that gives the info of all enterprise users? – auny May 16 '13 at 9:38
  • 2
    SELECT Id, Name, Email FROM Users will work, but you'll probably want to filter by profile ID or some other criteria. You can then build the ID URL yourself - it is https://login.salesforce.com/id/[ORG ID]/[USER ID] – metadaddy May 16 '13 at 17:10
7

There is an actual endpoint for this now as well: https://login.salesforce.com/services/oauth2/userinfo

See here for the help document

4

For Rest API (Force.com-JavaScript-REST-Toolkit), we have created one more API to get current authenticate user information. You can find more details at link

Please let me know in case of any other information required.

  • 1
    The code comment above the userInfo method really helped in understanding what was supposed to be passed as an argument. Thank You. – contactmatt Jul 16 '14 at 13:09
  • Most welcome contactmatt !!!! – Durgaprasad Budhwani Jul 16 '14 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.