Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extracting data out of AccessToken #28

Closed
quiKsilverItaly opened this issue Nov 8, 2016 · 4 comments
Closed

Extracting data out of AccessToken #28

quiKsilverItaly opened this issue Nov 8, 2016 · 4 comments

Comments

@quiKsilverItaly
Copy link

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
Copy link
Member

edjiang commented Nov 8, 2016

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": "[email protected]",
  "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 edjiang closed this as completed Nov 8, 2016
@edjiang
Copy link
Member

edjiang commented Nov 8, 2016

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

See #15

@quiKsilverItaly
Copy link
Author

quiKsilverItaly commented Nov 8, 2016

@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
Copy link
Member

edjiang commented Nov 8, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants