Нет описания

google.rb 951B

1234567891011121314151617181920212223242526272829303132
  1. module Oauth
  2. class Google < Oauth::Base
  3. ACCESS_TOKEN_URL = 'https://accounts.google.com/o/oauth2/token'
  4. DATA_URL = 'https://www.googleapis.com/plus/v1/people/me/openIdConnect'
  5. def get_names
  6. names = data[:name].try(:split).to_a
  7. [data[:given_name] || names.first, data[:family_name] || names.last]
  8. end
  9. def get_data
  10. response = @client.get(DATA_URL, access_token: @access_token)
  11. @data = JSON.parse(response.body).with_indifferent_access
  12. @uid = @data[:id] ||= @data[:sub]
  13. @data
  14. end
  15. def formatted_user_data
  16. {
  17. provider: 'google',
  18. token: @access_token,
  19. uid: @data['id'],
  20. first_name: @data['given_name'],
  21. last_name: @data['family_name'],
  22. email: @data['email'],
  23. image_url: @data['picture'].gsub("?sz=50", ""),
  24. google_profile: @data['profile']
  25. }
  26. end
  27. end
  28. end