Class: Redox::Authentication
Constant Summary
collapse
- BASE_ENDPOINT =
'/auth'.freeze
- AUTH_ENDPOINT =
"#{BASE_ENDPOINT}/authenticate".freeze
- REFRESH_ENDPOINT =
"#{BASE_ENDPOINT}/refreshToken".freeze
- @@token_expiry_padding =
0
Constants inherited
from Connection
Connection::DEFAULT_ENDPOINT
Class Attribute Summary collapse
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Connection
#request
Constructor Details
Returns a new instance of Authentication.
16
17
18
|
# File 'lib/redox/authentication.rb', line 16
def initialize
@response = nil
end
|
Class Attribute Details
.token_expiry_padding ⇒ Object
Returns the value of attribute token_expiry_padding.
11
12
13
|
# File 'lib/redox/authentication.rb', line 11
def token_expiry_padding
@token_expiry_padding
end
|
Instance Attribute Details
#response ⇒ Object
Returns the value of attribute response.
3
4
5
|
# File 'lib/redox/authentication.rb', line 3
def response
@response
end
|
Instance Method Details
67
68
69
70
71
|
# File 'lib/redox/authentication.rb', line 67
def
return {
'Authorization' => "Bearer #{self.access_token}",
}
end
|
#access_token ⇒ Object
47
48
49
|
# File 'lib/redox/authentication.rb', line 47
def access_token
return @response['accessToken'] if @response
end
|
#authenticate ⇒ Object
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
|
# File 'lib/redox/authentication.rb', line 20
def authenticate
if (self.expires?)
if (self.refresh_token)
request = {
body: { apiKey: Redox.configuration.api_key, refreshToken: self.refresh_token },
endpoint: REFRESH_ENDPOINT
}
else
request = {
body: { apiKey: Redox.configuration.api_key, secret: Redox.configuration.secret },
endpoint: AUTH_ENDPOINT
}
end
response = self.request(**request, auth: false)
if (false == response.ok?)
@response = nil
raise RedoxException.from_response(response, msg: 'Authentication')
else
@response = response
end
end
return self
end
|
#expire! ⇒ Object
73
74
75
|
# File 'lib/redox/authentication.rb', line 73
def expire!
@response = nil
end
|
#expires?(seconds_from_now = Authentication.token_expiry_padding) ⇒ Boolean
#expiry ⇒ Object
51
52
53
|
# File 'lib/redox/authentication.rb', line 51
def expiry
return @response['expires'] if @response
end
|
#refresh_token ⇒ Object
55
56
57
|
# File 'lib/redox/authentication.rb', line 55
def refresh_token
return @response['refreshToken'] if @response
end
|