Class: Code0::Identities::Provider::BaseOauth
- Inherits:
-
Object
- Object
- Code0::Identities::Provider::BaseOauth
show all
- Defined in:
- lib/code0/identities/provider/base_oauth.rb,
sig/code0/identities/provider/base_oauth.rbs
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(config_loader) ⇒ BaseOauth
Returns a new instance of BaseOauth.
9
10
11
|
# File 'lib/code0/identities/provider/base_oauth.rb', line 9
def initialize(config_loader)
@config_loader = config_loader
end
|
Instance Attribute Details
#config_loader ⇒ Proc, Hash[Symbol, any]
Returns the value of attribute config_loader.
7
8
9
|
# File 'lib/code0/identities/provider/base_oauth.rb', line 7
def config_loader
@config_loader
end
|
Instance Method Details
#access_token(code) ⇒ Array[String]
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/code0/identities/provider/base_oauth.rb', line 50
def access_token(code)
response = HTTParty.post(token_url,
body: URI.encode_www_form(token_payload(code)), headers: {
"Content-Type" => "application/x-www-form-urlencoded",
"Accept" => "application/json"
})
check_response response
parsed = response.parsed_response
[parsed["access_token"], parsed["token_type"]]
end
|
#authorization_url ⇒ String
17
18
19
|
# File 'lib/code0/identities/provider/base_oauth.rb', line 17
def authorization_url
raise NotImplementedError
end
|
#check_response(response) ⇒ void
This method returns an undefined value.
64
65
66
67
68
|
# File 'lib/code0/identities/provider/base_oauth.rb', line 64
def check_response(response)
return if response.code == 200
raise Error, response.body
end
|
#config ⇒ Hash[Symbol, any]
74
75
76
77
78
79
80
81
|
# File 'lib/code0/identities/provider/base_oauth.rb', line 74
def config
config = config_loader
config = config_loader.call if config_loader.is_a?(Proc)
config[:provider_name] ||= self.class.name.downcase.split("::").last
config
end
|
#create_identity(response, token, token_type) ⇒ Identity
70
71
72
|
# File 'lib/code0/identities/provider/base_oauth.rb', line 70
def create_identity(response, token, token_type)
raise NotImplementedError
end
|
#load_identity(**params) ⇒ Identity
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/code0/identities/provider/base_oauth.rb', line 33
def load_identity(**params)
code = params[:code]
token, token_type = access_token code
response = HTTParty.get(user_details_url,
headers: {
Authorization: "#{token_type} #{token}",
"Accept" => "application/json"
})
check_response response
create_identity response, token, token_type
end
|
#token_payload(code) ⇒ Hash[Symbol, any]
29
30
31
|
# File 'lib/code0/identities/provider/base_oauth.rb', line 29
def token_payload(code)
raise NotImplementedError
end
|
#token_url ⇒ String
21
22
23
|
# File 'lib/code0/identities/provider/base_oauth.rb', line 21
def token_url
raise NotImplementedError
end
|
#user_details_url ⇒ String
25
26
27
|
# File 'lib/code0/identities/provider/base_oauth.rb', line 25
def user_details_url
raise NotImplementedError
end
|
#validate_config! ⇒ void
This method returns an undefined value.
13
14
15
|
# File 'lib/code0/identities/provider/base_oauth.rb', line 13
def validate_config!
raise NotImplementedError
end
|