Simplicity icon indicating copy to clipboard operation
Simplicity copied to clipboard

How do i get user id and email from the access token ?

Open Dharin-shah opened this issue 9 years ago • 11 comments

Dharin-shah avatar Aug 12 '16 08:08 Dharin-shah

Hey @Dharin-shah, Simplicity is useful for obtaining an access token when you're using it for authentication with a backend server of your own. In that case, you'd implement the Facebook API / Google API / etc in your backend. If you'd like to make frontend calls to the Facebook / Google APIs, I'd recommend still using the Facebook / Google SDKs, as this is specifically for login.

Here's docs on how to build it into your backend:

https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow#checktoken https://developers.google.com/identity/protocols/OAuth2UserAgent#validatetoken

edjiang avatar Aug 13 '16 22:08 edjiang

Hey @edjiang thanks. I just wanted this lightweight library to do such stuff. Facebook and Google SDK weighs a lot leaving huge redundancy. Just for reference, I think directly calling the facebook api using the access token does the trick https://graph.facebook.com/me?access_token=<your_access_token> and for google plus https://www.googleapis.com/plus/v1/people/me?access_token=<your_access_token>

Dharin-shah avatar Aug 27 '16 04:08 Dharin-shah

Yeah, I think you're right -- changed my mind on this a bit. Maybe we should be adding this into Simplicity. If you're interested in contributing, I'm probably not going to work on this in the near future -- although I think we should wait until Swift 3 drops and stabilizes to continue work =]

edjiang avatar Aug 30 '16 20:08 edjiang

Sure. Thanks.

Dharin-shah avatar Sep 08 '16 05:09 Dharin-shah

Hello Dharin-shah, through the access token you can get name and id fields, but I haven't been able to get the email, have you been able to?

Marini83 avatar Oct 13 '16 21:10 Marini83

@Marini83 oh! I must have misunderstood your request. Yeah, you need to specifically request the scopes from Facebook.

Check out the docs here: https://github.com/SimplicityMobile/Simplicity#requesting-scopes-for-oauth-providers

edjiang avatar Oct 13 '16 21:10 edjiang

I stand corrected! I can't believe I didn't think of giving scope first, I thought it was all-inclusive. Thank you @edjiang ! So Dharin-shah could use the scope too correct?

Marini83 avatar Oct 13 '16 23:10 Marini83

@Dharin-shah's answer was pretty good, but if you want to get the user's Facebook email as well, you need to add an fields=name,email to the url:

https://graph.facebook.com/me?fields=email,name&access_token=[YourAccessToken]

lfarah avatar Jan 11 '17 04:01 lfarah

+1 for this feature in Simplicity.

kakubei avatar Mar 01 '17 14:03 kakubei

I've done it here: https://github.com/diegotrevisan/Simplicity.git

ghost avatar Sep 19 '17 12:09 ghost

Why dont you raise a pull request over here, sorry guys, was away for a while, got into a whole other project.

Dharin-shah avatar Dec 13 '17 19:12 Dharin-shah