SimplicityMobile / Simplicity

A simple way to implement Facebook and Google login in your iOS apps.
Apache License 2.0
681 stars 66 forks source link

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

Open Dharin-shah opened 7 years ago

edjiang commented 7 years ago

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

Dharin-shah commented 7 years ago

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= and for google plus https://www.googleapis.com/plus/v1/people/me?access_token=

edjiang commented 7 years ago

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 =]

Dharin-shah commented 7 years ago

Sure. Thanks.

Marini83 commented 7 years ago

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?

edjiang commented 7 years ago

@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

Marini83 commented 7 years ago

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?

lfarah commented 7 years ago

@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]
kakubei commented 7 years ago

+1 for this feature in Simplicity.

ghost commented 6 years ago

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

Dharin-shah commented 6 years ago

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