Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How could we get the user id in OAuth 2.0?

ANSWERED

May I ask how could we get the user id in OAuth 2.0? This looks like an obvious and simple question, but I find that I can not figure it out from the documentation. Thanks.

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

The user id is returned in the authorization callback. It's the "user_id" value.

 

An example from an implicit grant callback:

 

http://example.com/callback#scope=nutrition+weight+location+social+heartrate+settings+sleep+activity+profile&user_id=26FWFL&token_type=Bearer&expires_in=86400&access_token=eyJhbGciOiJIUzI1NiJ9.eyJleHAiOjE0NDgzMDg3MTUsInNjb3BlcyI6Indwcm8gd2xvYyB3bnV0IHdzbGUgd3NldCB3aHIgd3dlaSB3YWN0IHdzb2MiLCJzdWIiOiIyNkZXRkwiLCJhdWQiOiIyMjhZWDYiLCJpc3MiOiJGaXRiaXQiLCJ0eXAiOiJhY2Nlc3NfdG9rZW4iLCJpYXQiOjE0NDgyMjIzMTV9.pqf_QEb-Cbf6lb4JpOv-Nm0x2jcaW-w0LuLZ7RLkJfe

 

 

You can also request the user's profile, documented here. The user id is located in the response at user.encodedId .

View best answer in original post

Best Answer
0 Votes
6 REPLIES 6

The user id is returned in the authorization callback. It's the "user_id" value.

 

An example from an implicit grant callback:

 

http://example.com/callback#scope=nutrition+weight+location+social+heartrate+settings+sleep+activity+profile&user_id=26FWFL&token_type=Bearer&expires_in=86400&access_token=eyJhbGciOiJIUzI1NiJ9.eyJleHAiOjE0NDgzMDg3MTUsInNjb3BlcyI6Indwcm8gd2xvYyB3bnV0IHdzbGUgd3NldCB3aHIgd3dlaSB3YWN0IHdzb2MiLCJzdWIiOiIyNkZXRkwiLCJhdWQiOiIyMjhZWDYiLCJpc3MiOiJGaXRiaXQiLCJ0eXAiOiJhY2Nlc3NfdG9rZW4iLCJpYXQiOjE0NDgyMjIzMTV9.pqf_QEb-Cbf6lb4JpOv-Nm0x2jcaW-w0LuLZ7RLkJfe

 

 

You can also request the user's profile, documented here. The user id is located in the response at user.encodedId .

Best Answer
0 Votes

What about Authorization Code Grant Flow, I haven't find any way to get the user_id in the docs.

 

 

Best Answer
0 Votes

It is in the reponse when you try to get the access token as the parameter user_id. I think Fitbit should really put this on the doc (or put a sample of each response.)

Best Answer
0 Votes

@pyus13 wrote:

What about Authorization Code Grant Flow, I haven't find any way to get the user_id in the docs.


When using the Authorization Code Grant Flow, these values are returned in the Access Token Request.

Best Answer
0 Votes

@jlin wrote:

It is in the reponse when you try to get the access token as the parameter user_id. I think Fitbit should really put this on the doc (or put a sample of each response.)


I've updated the documentation to include the fragment parameters returned on the callback. (Because Fitbit's OAuth 2.0 implementation conforms to the RFC and is nearly identical to other implementations, our documentation is meant to complement, not replace, the RFC.)

 

The example for the Authorization Code Flow, which must use the Access Token Request, already had an example response.

Best Answer
0 Votes

Thank you so much, I really appreciate this. Yeah, when I implement the client for Fitbit OAuth 2.0, I have also refered the RFC document, it is very useful. I think the reason I have this user id question is that it is not a standard OAuth 2.0 parameter, which there is no documentation if it is not metioned in the Fitbit doc itself.

 

Thanks again.

Best Answer
0 Votes