-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgoogle.rb
More file actions
59 lines (48 loc) · 1.78 KB
/
Copy pathgoogle.rb
File metadata and controls
59 lines (48 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# frozen_string_literal: true
module Code0
module Identities
module Provider
class Google < BaseOauth
def validate_config!
required_keys = %i[redirect_uri client_id client_secret]
missing_keys = required_keys - config.keys
invalid_keys = config.keys - required_keys - [:provider_name]
raise MissingConfigurationError, "Missing: #{missing_keys.inspect}" if missing_keys.any?
raise InvalidConfigurationError, "Invalid: #{invalid_keys.inspect}" if invalid_keys.any?
end
def base_url
"https://accounts.google.com"
end
def token_url
"https://oauth2.googleapis.com/token"
end
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
def user_details_url
"https://www.googleapis.com/oauth2/v3/userinfo"
end
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
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(config[:provider_name], identifier, username, email, firstname, lastname)
end
end
end
end
end