-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitlab.rb
More file actions
55 lines (44 loc) · 1.61 KB
/
Copy pathgitlab.rb
File metadata and controls
55 lines (44 loc) · 1.61 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
# frozen_string_literal: true
module Code0
module Identities
module Provider
class Gitlab < BaseOauth
def validate_config!
required_keys = %i[base_url 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
config[:base_url]
end
def token_url
"#{base_url}/oauth/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
"#{base_url}/api/v4/user"
end
def authorization_url
# rubocop:disable Layout/LineLength
base_url + "/oauth/authorize?client_id=#{config[:client_id]}&response_type=code&redirect_uri=#{URI.encode_uri_component(config[:redirect_uri])}&scope=read_user"
# rubocop:enable Layout/LineLength
end
def create_identity(response, *)
body = response.parsed_response
identifier = body["id"]
username = body["username"]
email = body["email"]
Identity.new(config[:provider_name], identifier, username, email, nil, nil)
end
end
end
end
end