Skip to content

Instantly share code, notes, and snippets.

@mizalewski
Created April 24, 2016 11:01
Show Gist options
  • Save mizalewski/1b48b86771fc1ffb020f95387613331f to your computer and use it in GitHub Desktop.
Save mizalewski/1b48b86771fc1ffb020f95387613331f to your computer and use it in GitHub Desktop.
Get user info using OAuth2 (https://github.com/intridea/oauth2)
client = OAuth2::Client.new Figaro.env.omniauth_google_oauth2_app_id,
Figaro.env.omniauth_google_oauth2_app_secret,
{ site: 'https://accounts.google.com', authorize_url: '/o/oauth2/auth', token_url: '/o/oauth2/token' }
token = client.auth_code.get_token '4/authcode', {}
json = JSON.parse token.get('https://www.googleapis.com/plus/v1/people/me/openIdConnect').body
id = json['sub']
first_name = json['given_name']
last_name = json['family_name']
email = json['email']
email_verified = json['email_verified']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment