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

Extracting data out of AccessToken #28

Closed quiKsilverItaly closed 7 years ago

quiKsilverItaly commented 7 years ago

Hello there, thanks for this nice library.

The Google-Login works fine. Now I want to get the E-Mail-Information out of the AccessToken. Is this possible with your library? If not, what next step do you recommend? (For example picking up another library).

The thing is, getting the E-Mail out of access token is the only functionality I need, and using other Libs seems to be way too overkill for that.

Thanks in advance.

edjiang commented 7 years ago

Hey @quiKsilverItaly! This library is more meant to be used in the scenario where you send the access token to the backend, but in your scenario I can see how that's overkill as well.

To get the email, you could make this API call manually:

GET https://www.googleapis.com/oauth2/v3/userinfo?access_token=ACCESS_TOKEN_FROM_SIMPLICITY

It should return something like this:

{
  "sub": "113934915402034538610",
  "name": "Edward Jiang",
  "given_name": "Edward",
  "family_name": "Jiang",
  "profile": "https://plus.google.com/113934915402034538610",
  "picture": "https://lh6.googleusercontent.com/-eOdaSp-2dHY/AAAAAAAAAAI/AAAAAAAAABU/Z8_UB6zN_4I/photo.jpg",
  "email": "edward@stormpath.com",
  "email_verified": true,
  "gender": "male",
  "locale": "en"
}

So then you should be able to parse out the email!

Make sure that you request the email scope with Simplicity, though!

edjiang commented 7 years ago

If you want to write some code for this, I'd definitely want to incorporate this into Simplicity in the future.

See https://github.com/SimplicityMobile/Simplicity/issues/15

quiKsilverItaly commented 7 years ago

@edjiang I used the same solution like you recommended. Please note I used the libraries Alamofire (for HTTP-Connection) and SwiftyJSON (for extracting the JSON more easily) in my code.

This solution only currently supports Google devicetokens, but the two classes can be easily expanded with Facebook devicetoken and more.

http://pastebin.com/Y5J5EDgW

edjiang commented 7 years ago

Thanks! Yeah, the code to merge into Simplicity would take a little more work (no dependencies should be used, + this should be documented), but if it works for you I'm happy! =]