Class: Code0::Identities::Provider::Google

Inherits:
BaseOauth
  • Object
show all
Defined in:
lib/code0/identities/provider/google.rb

Instance Attribute Summary

Attributes inherited from BaseOauth

#config_loader

Instance Method Summary collapse

Methods inherited from BaseOauth

#initialize, #load_identity

Constructor Details

This class inherits a constructor from Code0::Identities::Provider::BaseOauth

Instance Method Details

#authorization_urlObject



29
30
31
32
33
# File 'lib/code0/identities/provider/google.rb', line 29

def authorization_url
  # rubocop:disable Layout/LineLength
  base_url + "/o/oauth2/v2/auth?client_id=#{config[:client_id]}&response_type=code&redirect_uri=#{URI.encode_www_form_component(config[:redirect_uri])}&scope=openid%20email%20profile"
  # rubocop:enable Layout/LineLength
end

#base_urlObject



7
8
9
# File 'lib/code0/identities/provider/google.rb', line 7

def base_url
  "https://accounts.google.com"
end

#create_identity(response) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/code0/identities/provider/google.rb', line 35

def create_identity(response, *)
  body = response.parsed_response

  identifier = body["sub"]
  username = body["name"]
  email = body["email"]
  firstname = body["given_name"]
  lastname = body["family_name"]

  Identity.new(:google, identifier, username, email, firstname, lastname)
end

#token_payload(code) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/code0/identities/provider/google.rb', line 15

def token_payload(code)
  {
    code: code,
    grant_type: "authorization_code",
    redirect_uri: config[:redirect_uri],
    client_id: config[:client_id],
    client_secret: config[:client_secret]
  }
end

#token_urlObject



11
12
13
# File 'lib/code0/identities/provider/google.rb', line 11

def token_url
  "https://oauth2.googleapis.com/token"
end

#user_details_urlObject



25
26
27
# File 'lib/code0/identities/provider/google.rb', line 25

def user_details_url
  "https://www.googleapis.com/oauth2/v3/userinfo"
end