colorado-booth-sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +28 -0
- data/README.md +202 -0
- data/bin/console +15 -0
- data/lib/multi_auth_sample/api_helper.rb +10 -0
- data/lib/multi_auth_sample/client.rb +118 -0
- data/lib/multi_auth_sample/configuration.rb +262 -0
- data/lib/multi_auth_sample/controllers/authentication_controller.rb +149 -0
- data/lib/multi_auth_sample/controllers/base_controller.rb +60 -0
- data/lib/multi_auth_sample/controllers/o_auth_authorization_controller.rb +188 -0
- data/lib/multi_auth_sample/exceptions/api_exception.rb +21 -0
- data/lib/multi_auth_sample/exceptions/o_auth_provider_exception.rb +64 -0
- data/lib/multi_auth_sample/http/auth/api_header.rb +59 -0
- data/lib/multi_auth_sample/http/auth/api_key.rb +59 -0
- data/lib/multi_auth_sample/http/auth/basic_auth.rb +62 -0
- data/lib/multi_auth_sample/http/auth/custom_auth.rb +40 -0
- data/lib/multi_auth_sample/http/auth/o_auth_acg.rb +163 -0
- data/lib/multi_auth_sample/http/auth/o_auth_bearer_token.rb +53 -0
- data/lib/multi_auth_sample/http/auth/o_auth_ccg.rb +148 -0
- data/lib/multi_auth_sample/http/auth/o_auth_ropcg.rb +139 -0
- data/lib/multi_auth_sample/http/http_call_back.rb +10 -0
- data/lib/multi_auth_sample/http/http_method_enum.rb +10 -0
- data/lib/multi_auth_sample/http/http_request.rb +10 -0
- data/lib/multi_auth_sample/http/http_response.rb +10 -0
- data/lib/multi_auth_sample/http/proxy_settings.rb +22 -0
- data/lib/multi_auth_sample/models/base_model.rb +122 -0
- data/lib/multi_auth_sample/models/o_auth_provider_error_enum.rb +62 -0
- data/lib/multi_auth_sample/models/o_auth_scope_o_auth_acg_enum.rb +26 -0
- data/lib/multi_auth_sample/models/o_auth_token.rb +106 -0
- data/lib/multi_auth_sample/models/service_status.rb +140 -0
- data/lib/multi_auth_sample/models/suite_code_enum.rb +50 -0
- data/lib/multi_auth_sample/models/user.rb +111 -0
- data/lib/multi_auth_sample/utilities/date_time_helper.rb +11 -0
- data/lib/multi_auth_sample/utilities/file_wrapper.rb +28 -0
- data/lib/multi_auth_sample.rb +55 -0
- data/test/controllers/controller_test_base.rb +60 -0
- data/test/controllers/test_authentication_controller.rb +110 -0
- data/test/http_response_catcher.rb +19 -0
- metadata +150 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# multi_auth_sample
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by APIMATIC v3.0
|
|
4
|
+
# ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module MultiAuthSample
|
|
7
|
+
# Utility class for custom authorization.
|
|
8
|
+
class CustomAuth < CoreLibrary::HeaderAuth
|
|
9
|
+
# Display error message on occurrence of authentication failure.
|
|
10
|
+
# @returns [String] The oAuth error message.
|
|
11
|
+
def error_message
|
|
12
|
+
# TODO: Add your error message here in case of failure in authentication
|
|
13
|
+
#
|
|
14
|
+
# Example:
|
|
15
|
+
# 'CustomAuth: config.access_token is undefined.'
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Initialization constructor.
|
|
19
|
+
def initialize(config)
|
|
20
|
+
auth_params = {}
|
|
21
|
+
|
|
22
|
+
# TODO: Add your custom authentication here
|
|
23
|
+
# The following properties are available to use
|
|
24
|
+
# auth_params['accessToken'] = config.access_token
|
|
25
|
+
|
|
26
|
+
super auth_params
|
|
27
|
+
@_config = config
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Validate arguments for authentication.
|
|
31
|
+
# @return [Boolean] true if the auth parameters are present.
|
|
32
|
+
def valid
|
|
33
|
+
# TODO: Add your validation checks here
|
|
34
|
+
#
|
|
35
|
+
# Example:
|
|
36
|
+
# return false unless @_config.access_token.nil?
|
|
37
|
+
true
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# multi_auth_sample
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by APIMATIC v3.0
|
|
4
|
+
# ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module MultiAuthSample
|
|
7
|
+
# Utility class for OAuth 2 authorization and token management.
|
|
8
|
+
class OAuthACG < CoreLibrary::HeaderAuth
|
|
9
|
+
include CoreLibrary
|
|
10
|
+
# Display error message on occurrence of authentication failure.
|
|
11
|
+
# @returns [String] The oAuth error message.
|
|
12
|
+
def error_message
|
|
13
|
+
'OAuthACG: OAuthToken is undefined or expired.'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Initialization constructor.
|
|
17
|
+
def initialize(o_auth_acg_credentials, config)
|
|
18
|
+
auth_params = {}
|
|
19
|
+
@_o_auth_client_id = o_auth_acg_credentials.o_auth_client_id unless
|
|
20
|
+
o_auth_acg_credentials.nil? || o_auth_acg_credentials.o_auth_client_id.nil?
|
|
21
|
+
@_o_auth_client_secret = o_auth_acg_credentials.o_auth_client_secret unless
|
|
22
|
+
o_auth_acg_credentials.nil? || o_auth_acg_credentials.o_auth_client_secret.nil?
|
|
23
|
+
@_o_auth_redirect_uri = o_auth_acg_credentials.o_auth_redirect_uri unless
|
|
24
|
+
o_auth_acg_credentials.nil? || o_auth_acg_credentials.o_auth_redirect_uri.nil?
|
|
25
|
+
@_o_auth_token = o_auth_acg_credentials.o_auth_token unless
|
|
26
|
+
o_auth_acg_credentials.nil? || o_auth_acg_credentials.o_auth_token.nil?
|
|
27
|
+
@_o_auth_scopes = o_auth_acg_credentials.o_auth_scopes unless
|
|
28
|
+
o_auth_acg_credentials.nil? || o_auth_acg_credentials.o_auth_scopes.nil?
|
|
29
|
+
@_config = config
|
|
30
|
+
@_o_auth_api = OAuthAuthorizationController.new(config)
|
|
31
|
+
auth_params[:Authorization] = "Bearer #{@_o_auth_token.access_token}" unless @_o_auth_token.nil?
|
|
32
|
+
|
|
33
|
+
super auth_params
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Validates the oAuth token.
|
|
37
|
+
# @return [Boolean] true if the token is present and not expired.
|
|
38
|
+
def valid
|
|
39
|
+
!@_o_auth_token.nil? && !token_expired?(@_o_auth_token)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Builds and returns an authorization URL.
|
|
43
|
+
# The user is expected to obtain an authorization code from this URL and then call the
|
|
44
|
+
# fetch token function with that authorization code.
|
|
45
|
+
# @param [String] state An opaque state string.
|
|
46
|
+
# @param [Hash] additional_params Any additional query parameters to be added to the URL.
|
|
47
|
+
# @return [String] The authorization URL.
|
|
48
|
+
def get_authorization_url(state: nil, additional_params: nil)
|
|
49
|
+
auth_url = @_config.get_base_uri_executor.call(Server::DEFAULT)
|
|
50
|
+
auth_url += '/oauth/authorize'
|
|
51
|
+
query_params = {
|
|
52
|
+
'response_type' => 'code',
|
|
53
|
+
'client_id' => @_o_auth_client_id,
|
|
54
|
+
'redirect_uri' => @_o_auth_redirect_uri
|
|
55
|
+
}
|
|
56
|
+
query_params['scope'] = Array(@_o_auth_scopes).compact.join(' ') if @_o_auth_scopes
|
|
57
|
+
query_params['state'] = state if state
|
|
58
|
+
query_params.merge!(additional_params) if additional_params
|
|
59
|
+
auth_url = APIHelper.append_url_with_query_parameters(auth_url,
|
|
60
|
+
query_params)
|
|
61
|
+
APIHelper.clean_url(auth_url)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Builds the basic auth header for endpoints in the OAuth Authorization Controller.
|
|
65
|
+
# @return [String] The value of the Authentication header.
|
|
66
|
+
def build_basic_auth_header
|
|
67
|
+
"Basic #{AuthHelper.get_base64_encoded_value(@_o_auth_client_id, @_o_auth_client_secret)}"
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Fetches the token.
|
|
71
|
+
# @param [String] auth_code The authentication code.
|
|
72
|
+
# @param [Hash] additional_params Any additional form parameters.
|
|
73
|
+
# @return [OAuthToken] The oAuth token instance.
|
|
74
|
+
def fetch_token(auth_code, additional_params: nil)
|
|
75
|
+
token = @_o_auth_api.request_token_o_auth_acg(
|
|
76
|
+
build_basic_auth_header,
|
|
77
|
+
auth_code,
|
|
78
|
+
@_o_auth_redirect_uri,
|
|
79
|
+
_field_parameters: additional_params
|
|
80
|
+
)
|
|
81
|
+
if token.respond_to?('expires_in') && !token.expires_in.nil?
|
|
82
|
+
token.expiry = AuthHelper.get_token_expiry(token.expires_in, Time.now.utc.to_i)
|
|
83
|
+
end
|
|
84
|
+
token
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Checks if OAuth token has expired.
|
|
88
|
+
# @param [OAuthToken] token The oAuth token instance.
|
|
89
|
+
# @return [Boolean] true if the token is present and not expired.
|
|
90
|
+
def token_expired?(token)
|
|
91
|
+
token.respond_to?('expiry') && AuthHelper.token_expired?(token.expiry)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Refreshes OAuth token.
|
|
95
|
+
# @param [Hash] additional_params Any additional form parameters.
|
|
96
|
+
# @return [OAuthToken] The oAuth token instance.
|
|
97
|
+
def refresh_token(additional_params: nil)
|
|
98
|
+
token = @_o_auth_api.refresh_token_o_auth_acg(
|
|
99
|
+
build_basic_auth_header,
|
|
100
|
+
@_o_auth_token.refresh_token,
|
|
101
|
+
scope: !@_o_auth_scopes.nil? ? Array(@_o_auth_scopes).compact.join(' ') : nil,
|
|
102
|
+
_field_parameters: additional_params
|
|
103
|
+
)
|
|
104
|
+
if token.respond_to?('expires_in') && !token.expires_in.nil?
|
|
105
|
+
token.expiry = AuthHelper.get_token_expiry(token.expires_in, Time.now.utc.to_i)
|
|
106
|
+
end
|
|
107
|
+
token
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# Data class for OAuthACGCredentials.
|
|
112
|
+
class OAuthACGCredentials
|
|
113
|
+
attr_reader :o_auth_client_id, :o_auth_client_secret, :o_auth_redirect_uri,
|
|
114
|
+
:o_auth_token, :o_auth_scopes
|
|
115
|
+
|
|
116
|
+
def initialize(o_auth_client_id:, o_auth_client_secret:,
|
|
117
|
+
o_auth_redirect_uri:, o_auth_token: nil, o_auth_scopes: nil)
|
|
118
|
+
raise ArgumentError, 'o_auth_client_id cannot be nil' if o_auth_client_id.nil?
|
|
119
|
+
raise ArgumentError, 'o_auth_client_secret cannot be nil' if o_auth_client_secret.nil?
|
|
120
|
+
raise ArgumentError, 'o_auth_redirect_uri cannot be nil' if o_auth_redirect_uri.nil?
|
|
121
|
+
|
|
122
|
+
@o_auth_client_id = o_auth_client_id
|
|
123
|
+
@o_auth_client_secret = o_auth_client_secret
|
|
124
|
+
@o_auth_redirect_uri = o_auth_redirect_uri
|
|
125
|
+
@o_auth_token = o_auth_token
|
|
126
|
+
@o_auth_scopes = o_auth_scopes
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def self.from_env
|
|
130
|
+
o_auth_client_id = ENV['O_AUTH_ACG_O_AUTH_CLIENT_ID']
|
|
131
|
+
o_auth_client_secret = ENV['O_AUTH_ACG_O_AUTH_CLIENT_SECRET']
|
|
132
|
+
o_auth_redirect_uri = ENV['O_AUTH_ACG_O_AUTH_REDIRECT_URI']
|
|
133
|
+
o_auth_scopes = ENV['O_AUTH_ACG_O_AUTH_SCOPES']
|
|
134
|
+
all_nil = [
|
|
135
|
+
o_auth_client_id,
|
|
136
|
+
o_auth_client_secret,
|
|
137
|
+
o_auth_redirect_uri
|
|
138
|
+
].all?(&:nil?)
|
|
139
|
+
return nil if all_nil
|
|
140
|
+
|
|
141
|
+
new(o_auth_client_id: o_auth_client_id,
|
|
142
|
+
o_auth_client_secret: o_auth_client_secret,
|
|
143
|
+
o_auth_redirect_uri: o_auth_redirect_uri,
|
|
144
|
+
o_auth_scopes: o_auth_scopes)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def clone_with(o_auth_client_id: nil, o_auth_client_secret: nil,
|
|
148
|
+
o_auth_redirect_uri: nil, o_auth_token: nil,
|
|
149
|
+
o_auth_scopes: nil)
|
|
150
|
+
o_auth_client_id ||= self.o_auth_client_id
|
|
151
|
+
o_auth_client_secret ||= self.o_auth_client_secret
|
|
152
|
+
o_auth_redirect_uri ||= self.o_auth_redirect_uri
|
|
153
|
+
o_auth_token ||= self.o_auth_token
|
|
154
|
+
o_auth_scopes ||= self.o_auth_scopes
|
|
155
|
+
|
|
156
|
+
OAuthACGCredentials.new(o_auth_client_id: o_auth_client_id,
|
|
157
|
+
o_auth_client_secret: o_auth_client_secret,
|
|
158
|
+
o_auth_redirect_uri: o_auth_redirect_uri,
|
|
159
|
+
o_auth_token: o_auth_token,
|
|
160
|
+
o_auth_scopes: o_auth_scopes)
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# multi_auth_sample
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by APIMATIC v3.0
|
|
4
|
+
# ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module MultiAuthSample
|
|
7
|
+
# Utility class for OAuth 2 authorization and token management.
|
|
8
|
+
class OAuthBearerToken < CoreLibrary::HeaderAuth
|
|
9
|
+
include CoreLibrary
|
|
10
|
+
# Display error message on occurrence of authentication failure.
|
|
11
|
+
# @returns [String] The oAuth error message.
|
|
12
|
+
def error_message
|
|
13
|
+
'OAuthBearerToken: access_token is undefined.'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Initialization constructor.
|
|
17
|
+
def initialize(o_auth_bearer_token_credentials)
|
|
18
|
+
auth_params = {}
|
|
19
|
+
@_access_token = o_auth_bearer_token_credentials.access_token unless
|
|
20
|
+
o_auth_bearer_token_credentials.nil? || o_auth_bearer_token_credentials.access_token.nil?
|
|
21
|
+
auth_params[:Authorization] = "Bearer #{@_access_token}" unless @_access_token.nil?
|
|
22
|
+
|
|
23
|
+
super auth_params
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Data class for OAuthBearerTokenCredentials.
|
|
28
|
+
class OAuthBearerTokenCredentials
|
|
29
|
+
attr_reader :access_token
|
|
30
|
+
|
|
31
|
+
def initialize(access_token:)
|
|
32
|
+
raise ArgumentError, 'access_token cannot be nil' if access_token.nil?
|
|
33
|
+
|
|
34
|
+
@access_token = access_token
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.from_env
|
|
38
|
+
access_token = ENV['O_AUTH_BEARER_TOKEN_ACCESS_TOKEN']
|
|
39
|
+
all_nil = [
|
|
40
|
+
access_token
|
|
41
|
+
].all?(&:nil?)
|
|
42
|
+
return nil if all_nil
|
|
43
|
+
|
|
44
|
+
new(access_token: access_token)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def clone_with(access_token: nil)
|
|
48
|
+
access_token ||= self.access_token
|
|
49
|
+
|
|
50
|
+
OAuthBearerTokenCredentials.new(access_token: access_token)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# multi_auth_sample
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by APIMATIC v3.0
|
|
4
|
+
# ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module MultiAuthSample
|
|
7
|
+
# Utility class for OAuth 2 authorization and token management.
|
|
8
|
+
class OAuthCCG < CoreLibrary::HeaderAuth
|
|
9
|
+
include CoreLibrary
|
|
10
|
+
# Display error message on occurrence of authentication failure.
|
|
11
|
+
# @returns [String] The oAuth error message.
|
|
12
|
+
def error_message
|
|
13
|
+
'OAuthCCG: OAuthToken is undefined or expired.'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Initialization constructor.
|
|
17
|
+
def initialize(o_auth_ccg_credentials, config)
|
|
18
|
+
@_o_auth_client_id = o_auth_ccg_credentials.o_auth_client_id unless
|
|
19
|
+
o_auth_ccg_credentials.nil? || o_auth_ccg_credentials.o_auth_client_id.nil?
|
|
20
|
+
@_o_auth_client_secret = o_auth_ccg_credentials.o_auth_client_secret unless
|
|
21
|
+
o_auth_ccg_credentials.nil? || o_auth_ccg_credentials.o_auth_client_secret.nil?
|
|
22
|
+
@_o_auth_token = o_auth_ccg_credentials.o_auth_token unless
|
|
23
|
+
o_auth_ccg_credentials.nil? || o_auth_ccg_credentials.o_auth_token.nil?
|
|
24
|
+
@_o_auth_clock_skew = o_auth_ccg_credentials.o_auth_clock_skew unless
|
|
25
|
+
o_auth_ccg_credentials.nil? || o_auth_ccg_credentials.o_auth_clock_skew.nil?
|
|
26
|
+
@_o_auth_token_provider = o_auth_ccg_credentials.o_auth_token_provider unless
|
|
27
|
+
o_auth_ccg_credentials.nil? || o_auth_ccg_credentials.o_auth_token_provider.nil?
|
|
28
|
+
@_o_auth_on_token_update = o_auth_ccg_credentials.o_auth_on_token_update unless
|
|
29
|
+
o_auth_ccg_credentials.nil? || o_auth_ccg_credentials.o_auth_on_token_update.nil?
|
|
30
|
+
@_o_auth_api = OAuthAuthorizationController.new(config)
|
|
31
|
+
super({})
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Validates the oAuth token.
|
|
35
|
+
# @return [Boolean] true if the token is present and not expired.
|
|
36
|
+
def valid
|
|
37
|
+
@_o_auth_token = get_token_from_provider
|
|
38
|
+
@_o_auth_token.is_a?(OAuthToken) && !token_expired?(@_o_auth_token)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Builds the basic auth header for endpoints in the OAuth Authorization Controller.
|
|
42
|
+
# @return [String] The value of the Authentication header.
|
|
43
|
+
def build_basic_auth_header
|
|
44
|
+
"Basic #{AuthHelper.get_base64_encoded_value(@_o_auth_client_id, @_o_auth_client_secret)}"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Fetches the token.
|
|
48
|
+
# @param [Hash] additional_params Any additional form parameters.
|
|
49
|
+
# @return [OAuthToken] The oAuth token instance.
|
|
50
|
+
def fetch_token(additional_params: nil)
|
|
51
|
+
token = @_o_auth_api.request_token_o_auth_ccg(
|
|
52
|
+
build_basic_auth_header,
|
|
53
|
+
_field_parameters: additional_params
|
|
54
|
+
)
|
|
55
|
+
if token.respond_to?('expires_in') && !token.expires_in.nil?
|
|
56
|
+
token.expiry = AuthHelper.get_token_expiry(token.expires_in, Time.now.utc.to_i)
|
|
57
|
+
end
|
|
58
|
+
token
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Checks if OAuth token has expired.
|
|
62
|
+
# @param [OAuthToken] token The oAuth token instance.
|
|
63
|
+
# @return [Boolean] true if the token's expiry exist and also the token is expired, false otherwise.
|
|
64
|
+
def token_expired?(token)
|
|
65
|
+
token.respond_to?('expiry') && AuthHelper.token_expired?(token.expiry, @_o_auth_clock_skew)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def apply(http_request)
|
|
69
|
+
auth_params = { 'Authorization' => "Bearer #{@_o_auth_token.access_token}" }
|
|
70
|
+
AuthHelper.apply(auth_params, http_request.method(:add_header))
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
private
|
|
74
|
+
|
|
75
|
+
# This provides the OAuth Token from either the user configured callbacks or from default provider.
|
|
76
|
+
# @return [OAuthToken] The fetched oauth token.
|
|
77
|
+
def get_token_from_provider
|
|
78
|
+
return @_o_auth_token if @_o_auth_token && !token_expired?(@_o_auth_token)
|
|
79
|
+
|
|
80
|
+
if @_o_auth_token_provider
|
|
81
|
+
o_auth_token = @_o_auth_token_provider.call(@_o_auth_token, self)
|
|
82
|
+
@_o_auth_on_token_update&.call(o_auth_token)
|
|
83
|
+
return o_auth_token
|
|
84
|
+
end
|
|
85
|
+
begin
|
|
86
|
+
o_auth_token = fetch_token
|
|
87
|
+
@_o_auth_on_token_update&.call(o_auth_token)
|
|
88
|
+
o_auth_token
|
|
89
|
+
rescue ApiException
|
|
90
|
+
@_o_auth_token
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# Data class for OAuthCCGCredentials.
|
|
96
|
+
class OAuthCCGCredentials
|
|
97
|
+
attr_reader :o_auth_client_id, :o_auth_client_secret, :o_auth_token,
|
|
98
|
+
:o_auth_token_provider, :o_auth_on_token_update,
|
|
99
|
+
:o_auth_clock_skew
|
|
100
|
+
|
|
101
|
+
def initialize(o_auth_client_id:, o_auth_client_secret:, o_auth_token: nil,
|
|
102
|
+
o_auth_token_provider: nil, o_auth_on_token_update: nil,
|
|
103
|
+
o_auth_clock_skew: 0)
|
|
104
|
+
raise ArgumentError, 'o_auth_client_id cannot be nil' if o_auth_client_id.nil?
|
|
105
|
+
raise ArgumentError, 'o_auth_client_secret cannot be nil' if o_auth_client_secret.nil?
|
|
106
|
+
|
|
107
|
+
@o_auth_client_id = o_auth_client_id
|
|
108
|
+
@o_auth_client_secret = o_auth_client_secret
|
|
109
|
+
@o_auth_token = o_auth_token
|
|
110
|
+
@o_auth_token_provider = o_auth_token_provider
|
|
111
|
+
@o_auth_on_token_update = o_auth_on_token_update
|
|
112
|
+
@o_auth_clock_skew = o_auth_clock_skew
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def self.from_env
|
|
116
|
+
o_auth_client_id = ENV['O_AUTH_CCG_O_AUTH_CLIENT_ID']
|
|
117
|
+
o_auth_client_secret = ENV['O_AUTH_CCG_O_AUTH_CLIENT_SECRET']
|
|
118
|
+
o_auth_clock_skew = ENV['O_AUTH_CCG_O_AUTH_CLOCK_SKEW']
|
|
119
|
+
all_nil = [
|
|
120
|
+
o_auth_client_id,
|
|
121
|
+
o_auth_client_secret
|
|
122
|
+
].all?(&:nil?)
|
|
123
|
+
return nil if all_nil
|
|
124
|
+
|
|
125
|
+
new(o_auth_client_id: o_auth_client_id,
|
|
126
|
+
o_auth_client_secret: o_auth_client_secret,
|
|
127
|
+
o_auth_clock_skew: o_auth_clock_skew)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def clone_with(o_auth_client_id: nil, o_auth_client_secret: nil,
|
|
131
|
+
o_auth_token: nil, o_auth_token_provider: nil,
|
|
132
|
+
o_auth_on_token_update: nil, o_auth_clock_skew: nil)
|
|
133
|
+
o_auth_client_id ||= self.o_auth_client_id
|
|
134
|
+
o_auth_client_secret ||= self.o_auth_client_secret
|
|
135
|
+
o_auth_token ||= self.o_auth_token
|
|
136
|
+
o_auth_token_provider ||= self.o_auth_token_provider
|
|
137
|
+
o_auth_on_token_update ||= self.o_auth_on_token_update
|
|
138
|
+
o_auth_clock_skew ||= self.o_auth_clock_skew
|
|
139
|
+
|
|
140
|
+
OAuthCCGCredentials.new(o_auth_client_id: o_auth_client_id,
|
|
141
|
+
o_auth_client_secret: o_auth_client_secret,
|
|
142
|
+
o_auth_token: o_auth_token,
|
|
143
|
+
o_auth_token_provider: o_auth_token_provider,
|
|
144
|
+
o_auth_on_token_update: o_auth_on_token_update,
|
|
145
|
+
o_auth_clock_skew: o_auth_clock_skew)
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
end
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# multi_auth_sample
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by APIMATIC v3.0
|
|
4
|
+
# ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module MultiAuthSample
|
|
7
|
+
# Utility class for OAuth 2 authorization and token management.
|
|
8
|
+
class OAuthROPCG < CoreLibrary::HeaderAuth
|
|
9
|
+
include CoreLibrary
|
|
10
|
+
# Display error message on occurrence of authentication failure.
|
|
11
|
+
# @returns [String] The oAuth error message.
|
|
12
|
+
def error_message
|
|
13
|
+
'OAuthROPCG: OAuthToken is undefined or expired.'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Initialization constructor.
|
|
17
|
+
def initialize(o_auth_ropcg_credentials, config)
|
|
18
|
+
auth_params = {}
|
|
19
|
+
@_o_auth_client_id = o_auth_ropcg_credentials.o_auth_client_id unless
|
|
20
|
+
o_auth_ropcg_credentials.nil? || o_auth_ropcg_credentials.o_auth_client_id.nil?
|
|
21
|
+
@_o_auth_client_secret = o_auth_ropcg_credentials.o_auth_client_secret unless
|
|
22
|
+
o_auth_ropcg_credentials.nil? || o_auth_ropcg_credentials.o_auth_client_secret.nil?
|
|
23
|
+
@_o_auth_username = o_auth_ropcg_credentials.o_auth_username unless
|
|
24
|
+
o_auth_ropcg_credentials.nil? || o_auth_ropcg_credentials.o_auth_username.nil?
|
|
25
|
+
@_o_auth_password = o_auth_ropcg_credentials.o_auth_password unless
|
|
26
|
+
o_auth_ropcg_credentials.nil? || o_auth_ropcg_credentials.o_auth_password.nil?
|
|
27
|
+
@_o_auth_token = o_auth_ropcg_credentials.o_auth_token unless
|
|
28
|
+
o_auth_ropcg_credentials.nil? || o_auth_ropcg_credentials.o_auth_token.nil?
|
|
29
|
+
@_o_auth_api = OAuthAuthorizationController.new(config)
|
|
30
|
+
auth_params[:Authorization] = "Bearer #{@_o_auth_token.access_token}" unless @_o_auth_token.nil?
|
|
31
|
+
|
|
32
|
+
super auth_params
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Validates the oAuth token.
|
|
36
|
+
# @return [Boolean] true if the token is present and not expired.
|
|
37
|
+
def valid
|
|
38
|
+
!@_o_auth_token.nil? && !token_expired?(@_o_auth_token)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Builds the basic auth header for endpoints in the OAuth Authorization Controller.
|
|
42
|
+
# @return [String] The value of the Authentication header.
|
|
43
|
+
def build_basic_auth_header
|
|
44
|
+
"Basic #{AuthHelper.get_base64_encoded_value(@_o_auth_client_id, @_o_auth_client_secret)}"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Fetches the token.
|
|
48
|
+
# @param [Hash] additional_params Any additional form parameters.
|
|
49
|
+
# @return [OAuthToken] The oAuth token instance.
|
|
50
|
+
def fetch_token(additional_params: nil)
|
|
51
|
+
token = @_o_auth_api.request_token_o_auth_ropcg(
|
|
52
|
+
build_basic_auth_header,
|
|
53
|
+
@_o_auth_username,
|
|
54
|
+
@_o_auth_password,
|
|
55
|
+
_field_parameters: additional_params
|
|
56
|
+
)
|
|
57
|
+
if token.respond_to?('expires_in') && !token.expires_in.nil?
|
|
58
|
+
token.expiry = AuthHelper.get_token_expiry(token.expires_in, Time.now.utc.to_i)
|
|
59
|
+
end
|
|
60
|
+
token
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Checks if OAuth token has expired.
|
|
64
|
+
# @param [OAuthToken] token The oAuth token instance.
|
|
65
|
+
# @return [Boolean] true if the token is present and not expired.
|
|
66
|
+
def token_expired?(token)
|
|
67
|
+
token.respond_to?('expiry') && AuthHelper.token_expired?(token.expiry)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Refreshes OAuth token.
|
|
71
|
+
# @param [Hash] additional_params Any additional form parameters.
|
|
72
|
+
# @return [OAuthToken] The oAuth token instance.
|
|
73
|
+
def refresh_token(additional_params: nil)
|
|
74
|
+
token = @_o_auth_api.refresh_token_o_auth_ropcg(
|
|
75
|
+
build_basic_auth_header,
|
|
76
|
+
@_o_auth_token.refresh_token,
|
|
77
|
+
_field_parameters: additional_params
|
|
78
|
+
)
|
|
79
|
+
if token.respond_to?('expires_in') && !token.expires_in.nil?
|
|
80
|
+
token.expiry = AuthHelper.get_token_expiry(token.expires_in, Time.now.utc.to_i)
|
|
81
|
+
end
|
|
82
|
+
token
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Data class for OAuthROPCGCredentials.
|
|
87
|
+
class OAuthROPCGCredentials
|
|
88
|
+
attr_reader :o_auth_client_id, :o_auth_client_secret, :o_auth_username,
|
|
89
|
+
:o_auth_password, :o_auth_token
|
|
90
|
+
|
|
91
|
+
def initialize(o_auth_client_id:, o_auth_client_secret:, o_auth_username:,
|
|
92
|
+
o_auth_password:, o_auth_token: nil)
|
|
93
|
+
raise ArgumentError, 'o_auth_client_id cannot be nil' if o_auth_client_id.nil?
|
|
94
|
+
raise ArgumentError, 'o_auth_client_secret cannot be nil' if o_auth_client_secret.nil?
|
|
95
|
+
raise ArgumentError, 'o_auth_username cannot be nil' if o_auth_username.nil?
|
|
96
|
+
raise ArgumentError, 'o_auth_password cannot be nil' if o_auth_password.nil?
|
|
97
|
+
|
|
98
|
+
@o_auth_client_id = o_auth_client_id
|
|
99
|
+
@o_auth_client_secret = o_auth_client_secret
|
|
100
|
+
@o_auth_username = o_auth_username
|
|
101
|
+
@o_auth_password = o_auth_password
|
|
102
|
+
@o_auth_token = o_auth_token
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def self.from_env
|
|
106
|
+
o_auth_client_id = ENV['O_AUTH_ROPCG_O_AUTH_CLIENT_ID']
|
|
107
|
+
o_auth_client_secret = ENV['O_AUTH_ROPCG_O_AUTH_CLIENT_SECRET']
|
|
108
|
+
o_auth_username = ENV['O_AUTH_ROPCG_O_AUTH_USERNAME']
|
|
109
|
+
o_auth_password = ENV['O_AUTH_ROPCG_O_AUTH_PASSWORD']
|
|
110
|
+
all_nil = [
|
|
111
|
+
o_auth_client_id,
|
|
112
|
+
o_auth_client_secret,
|
|
113
|
+
o_auth_username,
|
|
114
|
+
o_auth_password
|
|
115
|
+
].all?(&:nil?)
|
|
116
|
+
return nil if all_nil
|
|
117
|
+
|
|
118
|
+
new(o_auth_client_id: o_auth_client_id,
|
|
119
|
+
o_auth_client_secret: o_auth_client_secret,
|
|
120
|
+
o_auth_username: o_auth_username, o_auth_password: o_auth_password)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def clone_with(o_auth_client_id: nil, o_auth_client_secret: nil,
|
|
124
|
+
o_auth_username: nil, o_auth_password: nil,
|
|
125
|
+
o_auth_token: nil)
|
|
126
|
+
o_auth_client_id ||= self.o_auth_client_id
|
|
127
|
+
o_auth_client_secret ||= self.o_auth_client_secret
|
|
128
|
+
o_auth_username ||= self.o_auth_username
|
|
129
|
+
o_auth_password ||= self.o_auth_password
|
|
130
|
+
o_auth_token ||= self.o_auth_token
|
|
131
|
+
|
|
132
|
+
OAuthROPCGCredentials.new(o_auth_client_id: o_auth_client_id,
|
|
133
|
+
o_auth_client_secret: o_auth_client_secret,
|
|
134
|
+
o_auth_username: o_auth_username,
|
|
135
|
+
o_auth_password: o_auth_password,
|
|
136
|
+
o_auth_token: o_auth_token)
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# multi_auth_sample
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by APIMATIC v3.0
|
|
4
|
+
# ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module MultiAuthSample
|
|
7
|
+
# HttpCallBack allows defining callables for pre and post API calls.
|
|
8
|
+
class HttpCallBack < CoreLibrary::HttpCallback
|
|
9
|
+
end
|
|
10
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# multi_auth_sample
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by APIMATIC v3.0
|
|
4
|
+
# ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module MultiAuthSample
|
|
7
|
+
##
|
|
8
|
+
# ProxySettings encapsulates HTTP proxy configuration for Faraday,
|
|
9
|
+
# including optional basic authentication.
|
|
10
|
+
#
|
|
11
|
+
class ProxySettings < CoreLibrary::ProxySettings
|
|
12
|
+
def self.from_env
|
|
13
|
+
address = ENV['PROXY_ADDRESS']
|
|
14
|
+
port = ENV['PROXY_PORT']
|
|
15
|
+
username = ENV['PROXY_USERNAME']
|
|
16
|
+
password = ENV['PROXY_PASSWORD']
|
|
17
|
+
return nil if address.nil? || address.strip.empty?
|
|
18
|
+
|
|
19
|
+
new(address: address, port: port, username: username, password: password)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|