Class: CoreLibrary::AuthHelper
- Inherits:
-
Object
- Object
- CoreLibrary::AuthHelper
- Defined in:
- lib/apimatic-core/utilities/auth_helper.rb
Overview
A utility class for authentication flow
Class Method Summary collapse
-
.apply(auth_params, func) ⇒ Object
Applies callable to each entry of the hash.
-
.get_base64_encoded_value(*props, delimiter: ':') ⇒ String
Performs the Base64 encodes the provided parameters after joining the parameters with delimiter.
-
.get_token_expiry(expires_in, current_timestamp) ⇒ Time
Calculates the expiry after adding the expires_in value to the current timestamp.
-
.token_expired?(token_expiry, clock_skew_time = nil) ⇒ Boolean
Checks if OAuth token has expired.
-
.valid_auth?(auth_params) ⇒ Boolean
Checks whether the provided auth parameters does not contain any nil key/value.
Class Method Details
.apply(auth_params, func) ⇒ Object
Applies callable to each entry of the hash.
47 48 49 |
# File 'lib/apimatic-core/utilities/auth_helper.rb', line 47 def self.apply(auth_params, func) auth_params.each { |key, value| func.call(key, value) } end |
.get_base64_encoded_value(*props, delimiter: ':') ⇒ String
Performs the Base64 encodes the provided parameters after joining the parameters with delimiter.
10 11 12 13 14 15 |
# File 'lib/apimatic-core/utilities/auth_helper.rb', line 10 def self.get_base64_encoded_value(*props, delimiter: ':') return if props.any?(&:nil?) joined = props.join(delimiter) Base64.strict_encode64(joined) end |
.get_token_expiry(expires_in, current_timestamp) ⇒ Time
Calculates the expiry after adding the expires_in value to the current timestamp.
32 33 34 |
# File 'lib/apimatic-core/utilities/auth_helper.rb', line 32 def self.get_token_expiry(expires_in, ) + expires_in end |
.token_expired?(token_expiry, clock_skew_time = nil) ⇒ Boolean
Checks if OAuth token has expired.
21 22 23 24 25 26 |
# File 'lib/apimatic-core/utilities/auth_helper.rb', line 21 def self.token_expired?(token_expiry, clock_skew_time = nil) raise ArgumentError, 'Token expiry can not be nil.' if token_expiry.nil? token_expiry -= clock_skew_time unless clock_skew_time.nil? token_expiry < Time.now.utc.to_i end |
.valid_auth?(auth_params) ⇒ Boolean
Checks whether the provided auth parameters does not contain any nil key/value.
39 40 41 42 |
# File 'lib/apimatic-core/utilities/auth_helper.rb', line 39 def self.valid_auth?(auth_params) !auth_params.nil? and !auth_params.empty? and auth_params.all? { |key, value| !(key.nil? or value.nil?) } end |