multi-auth-project-sdk 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +28 -0
  3. data/README.md +139 -0
  4. data/lib/multi_auth_sample/api_helper.rb +10 -0
  5. data/lib/multi_auth_sample/client.rb +105 -0
  6. data/lib/multi_auth_sample/configuration.rb +170 -0
  7. data/lib/multi_auth_sample/controllers/authentication_controller.rb +151 -0
  8. data/lib/multi_auth_sample/controllers/base_controller.rb +65 -0
  9. data/lib/multi_auth_sample/controllers/o_auth_authorization_controller.rb +188 -0
  10. data/lib/multi_auth_sample/exceptions/api_exception.rb +10 -0
  11. data/lib/multi_auth_sample/exceptions/o_auth_provider_exception.rb +48 -0
  12. data/lib/multi_auth_sample/http/auth/api_header.rb +47 -0
  13. data/lib/multi_auth_sample/http/auth/api_key.rb +47 -0
  14. data/lib/multi_auth_sample/http/auth/basic_auth.rb +49 -0
  15. data/lib/multi_auth_sample/http/auth/custom_auth.rb +40 -0
  16. data/lib/multi_auth_sample/http/auth/o_auth_acg.rb +144 -0
  17. data/lib/multi_auth_sample/http/auth/o_auth_bearer_token.rb +42 -0
  18. data/lib/multi_auth_sample/http/auth/o_auth_ccg.rb +88 -0
  19. data/lib/multi_auth_sample/http/auth/o_auth_ropcg.rb +120 -0
  20. data/lib/multi_auth_sample/http/http_call_back.rb +10 -0
  21. data/lib/multi_auth_sample/http/http_method_enum.rb +10 -0
  22. data/lib/multi_auth_sample/http/http_request.rb +10 -0
  23. data/lib/multi_auth_sample/http/http_response.rb +10 -0
  24. data/lib/multi_auth_sample/models/base_model.rb +62 -0
  25. data/lib/multi_auth_sample/models/o_auth_provider_error_enum.rb +45 -0
  26. data/lib/multi_auth_sample/models/o_auth_scope_o_auth_acg_enum.rb +20 -0
  27. data/lib/multi_auth_sample/models/o_auth_token.rb +110 -0
  28. data/lib/multi_auth_sample/models/service_status.rb +129 -0
  29. data/lib/multi_auth_sample/models/suite_code_enum.rb +29 -0
  30. data/lib/multi_auth_sample/models/user.rb +100 -0
  31. data/lib/multi_auth_sample/utilities/date_time_helper.rb +11 -0
  32. data/lib/multi_auth_sample/utilities/file_wrapper.rb +16 -0
  33. data/lib/multi_auth_sample.rb +54 -0
  34. data/test/controllers/controller_test_base.rb +47 -0
  35. data/test/controllers/test_authentication_controller.rb +110 -0
  36. data/test/http_response_catcher.rb +19 -0
  37. metadata +154 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 73adfbae8c46203f3325a8b1e4e635c86dbce96c6051cc11c5fe7cc6da411b68
4
+ data.tar.gz: 8a3bf977e8cd7f26461b29decccfe400715e975323a87dd41e7a29edfeebe449
5
+ SHA512:
6
+ metadata.gz: 20342014477da699b5fd336c3030f65263eab1fe20dbe9abcff39658f2f536a7eaa10d0a91d173bea5c71dd032f2716e7721017c597bf2ac542dc8d0fe2cc7f5
7
+ data.tar.gz: 99ebfa93f0ef07fa8854c9cdacef30179008efc64adeecf5f3c70919509d2a79a2bf70743f8c30a7661b68c52479856120e488fc2739f07eab899e8d58a46c5b
data/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ License:
2
+ ========
3
+ The MIT License (MIT)
4
+ http://opensource.org/licenses/MIT
5
+
6
+ Copyright (c) 2014 - 2024 APIMATIC Limited
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in
16
+ all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ THE SOFTWARE.
25
+
26
+ Trade Mark:
27
+ ==========
28
+ APIMATIC is a trade mark for APIMATIC Limited
data/README.md ADDED
@@ -0,0 +1,139 @@
1
+
2
+ # Getting Started with MultiAuth-Sample
3
+
4
+ ## Introduction
5
+
6
+ API for Markdown Notes app.
7
+
8
+ ## Install the Package
9
+
10
+ Install the gem from the command line:
11
+
12
+ ```ruby
13
+ gem install multi-auth-project-sdk -v 1.0.0
14
+ ```
15
+
16
+ Or add the gem to your Gemfile and run `bundle`:
17
+
18
+ ```ruby
19
+ gem 'multi-auth-project-sdk', '1.0.0'
20
+ ```
21
+
22
+ For additional gem details, see the [RubyGems page for the multi-auth-project-sdk gem](https://rubygems.org/gems/multi-auth-project-sdk/versions/1.0.0).
23
+
24
+ ## Test the SDK
25
+
26
+ To run the tests, navigate to the root directory of the SDK in your terminal and execute the following command:
27
+
28
+ ```
29
+ rake
30
+ ```
31
+
32
+ ## Initialize the API Client
33
+
34
+ **_Note:_** Documentation for the client can be found [here.](https://www.github.com/Syed-Subtain/multi-auth-project-ruby-sdk/tree/1.0.0/doc/client.md)
35
+
36
+ The following parameters are configurable for the API Client:
37
+
38
+ | Parameter | Type | Description |
39
+ | --- | --- | --- |
40
+ | `access_token` | `String` | |
41
+ | `port` | `String` | *Default*: `'80'` |
42
+ | `suites` | `SuiteCodeEnum` | *Default*: `SuiteCodeEnum::HEARTS` |
43
+ | `environment` | Environment | The API environment. <br> **Default: `Environment.TESTING`** |
44
+ | `connection` | `Faraday::Connection` | The Faraday connection object passed by the SDK user for making requests |
45
+ | `adapter` | `Faraday::Adapter` | The Faraday adapter object passed by the SDK user for performing http requests |
46
+ | `timeout` | `Float` | The value to use for connection timeout. <br> **Default: 60** |
47
+ | `max_retries` | `Integer` | The number of times to retry an endpoint call if it fails. <br> **Default: 0** |
48
+ | `retry_interval` | `Float` | Pause in seconds between retries. <br> **Default: 1** |
49
+ | `backoff_factor` | `Float` | The amount to multiply each successive retry's interval amount by in order to provide backoff. <br> **Default: 2** |
50
+ | `retry_statuses` | `Array` | A list of HTTP statuses to retry. <br> **Default: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524]** |
51
+ | `retry_methods` | `Array` | A list of HTTP methods to retry. <br> **Default: %i[get put]** |
52
+ | `http_callback` | `HttpCallBack` | The Http CallBack allows defining callables for pre and post API calls. |
53
+ | `basic_auth_credentials` | [`BasicAuthCredentials`](https://www.github.com/Syed-Subtain/multi-auth-project-ruby-sdk/tree/1.0.0/doc/$a/https://www.github.com/Syed-Subtain/multi-auth-project-ruby-sdk/tree/1.0.0/basic-authentication.md) | The credential object for Basic Authentication |
54
+ | `api_key_credentials` | [`ApiKeyCredentials`](https://www.github.com/Syed-Subtain/multi-auth-project-ruby-sdk/tree/1.0.0/doc/$a/https://www.github.com/Syed-Subtain/multi-auth-project-ruby-sdk/tree/1.0.0/custom-query-parameter.md) | The credential object for Custom Query Parameter |
55
+ | `api_header_credentials` | [`ApiHeaderCredentials`](https://www.github.com/Syed-Subtain/multi-auth-project-ruby-sdk/tree/1.0.0/doc/$a/https://www.github.com/Syed-Subtain/multi-auth-project-ruby-sdk/tree/1.0.0/custom-header-signature.md) | The credential object for Custom Header Signature |
56
+ | `o_auth_ccg_credentials` | [`OAuthCCGCredentials`](https://www.github.com/Syed-Subtain/multi-auth-project-ruby-sdk/tree/1.0.0/doc/$a/https://www.github.com/Syed-Subtain/multi-auth-project-ruby-sdk/tree/1.0.0/oauth-2-client-credentials-grant.md) | The credential object for OAuth 2 Client Credentials Grant |
57
+ | `o_auth_acg_credentials` | [`OAuthACGCredentials`](https://www.github.com/Syed-Subtain/multi-auth-project-ruby-sdk/tree/1.0.0/doc/$a/https://www.github.com/Syed-Subtain/multi-auth-project-ruby-sdk/tree/1.0.0/oauth-2-authorization-code-grant.md) | The credential object for OAuth 2 Authorization Code Grant |
58
+ | `o_auth_ropcg_credentials` | [`OAuthROPCGCredentials`](https://www.github.com/Syed-Subtain/multi-auth-project-ruby-sdk/tree/1.0.0/doc/$a/https://www.github.com/Syed-Subtain/multi-auth-project-ruby-sdk/tree/1.0.0/oauth-2-resource-owner-credentials-grant.md) | The credential object for OAuth 2 Resource Owner Credentials Grant |
59
+ | `o_auth_bearer_token_credentials` | [`OAuthBearerTokenCredentials`](https://www.github.com/Syed-Subtain/multi-auth-project-ruby-sdk/tree/1.0.0/doc/$a/https://www.github.com/Syed-Subtain/multi-auth-project-ruby-sdk/tree/1.0.0/oauth-2-bearer-token.md) | The credential object for OAuth 2 Bearer token |
60
+
61
+ The API client can be initialized as follows:
62
+
63
+ ```ruby
64
+ client = MultiAuthSample::Client.new(
65
+ access_token: 'accessToken',
66
+ basic_auth_credentials: BasicAuthCredentials.new(
67
+ username: 'Username',
68
+ password: 'Password'
69
+ ),
70
+ api_key_credentials: ApiKeyCredentials.new(
71
+ token: 'token',
72
+ api_key: 'api-key'
73
+ ),
74
+ api_header_credentials: ApiHeaderCredentials.new(
75
+ token: 'token',
76
+ api_key: 'api-key'
77
+ ),
78
+ o_auth_ccg_credentials: OAuthCCGCredentials.new(
79
+ o_auth_client_id: 'OAuthClientId',
80
+ o_auth_client_secret: 'OAuthClientSecret'
81
+ ),
82
+ o_auth_acg_credentials: OAuthACGCredentials.new(
83
+ o_auth_client_id: 'OAuthClientId',
84
+ o_auth_client_secret: 'OAuthClientSecret',
85
+ o_auth_redirect_uri: 'OAuthRedirectUri',
86
+ o_auth_scopes: [
87
+ OAuthScopeOAuthACGEnum::READ_SCOPE
88
+ ]
89
+ ),
90
+ o_auth_ropcg_credentials: OAuthROPCGCredentials.new(
91
+ o_auth_client_id: 'OAuthClientId',
92
+ o_auth_client_secret: 'OAuthClientSecret',
93
+ o_auth_username: 'OAuthUsername',
94
+ o_auth_password: 'OAuthPassword'
95
+ ),
96
+ o_auth_bearer_token_credentials: OAuthBearerTokenCredentials.new(
97
+ access_token: 'AccessToken'
98
+ ),
99
+ environment: Environment::TESTING,
100
+ port: '80',
101
+ suites: SuiteCodeEnum::HEARTS
102
+ )
103
+ ```
104
+
105
+ ## Environments
106
+
107
+ The SDK can be configured to use a different environment for making API calls. Available environments are:
108
+
109
+ ### Fields
110
+
111
+ | Name | Description |
112
+ | --- | --- |
113
+ | production | - |
114
+ | testing | **Default** |
115
+
116
+ ## Authorization
117
+
118
+ This API uses the following authentication schemes.
119
+
120
+ * [`basicAuth (Basic Authentication)`](https://www.github.com/Syed-Subtain/multi-auth-project-ruby-sdk/tree/1.0.0/doc/$a/https://www.github.com/Syed-Subtain/multi-auth-project-ruby-sdk/tree/1.0.0/basic-authentication.md)
121
+ * [`apiKey (Custom Query Parameter)`](https://www.github.com/Syed-Subtain/multi-auth-project-ruby-sdk/tree/1.0.0/doc/$a/https://www.github.com/Syed-Subtain/multi-auth-project-ruby-sdk/tree/1.0.0/custom-query-parameter.md)
122
+ * [`apiHeader (Custom Header Signature)`](https://www.github.com/Syed-Subtain/multi-auth-project-ruby-sdk/tree/1.0.0/doc/$a/https://www.github.com/Syed-Subtain/multi-auth-project-ruby-sdk/tree/1.0.0/custom-header-signature.md)
123
+ * [`OAuthCCG (OAuth 2 Client Credentials Grant)`](https://www.github.com/Syed-Subtain/multi-auth-project-ruby-sdk/tree/1.0.0/doc/$a/https://www.github.com/Syed-Subtain/multi-auth-project-ruby-sdk/tree/1.0.0/oauth-2-client-credentials-grant.md)
124
+ * [`OAuthACG (OAuth 2 Authorization Code Grant)`](https://www.github.com/Syed-Subtain/multi-auth-project-ruby-sdk/tree/1.0.0/doc/$a/https://www.github.com/Syed-Subtain/multi-auth-project-ruby-sdk/tree/1.0.0/oauth-2-authorization-code-grant.md)
125
+ * [`OAuthROPCG (OAuth 2 Resource Owner Credentials Grant)`](https://www.github.com/Syed-Subtain/multi-auth-project-ruby-sdk/tree/1.0.0/doc/$a/https://www.github.com/Syed-Subtain/multi-auth-project-ruby-sdk/tree/1.0.0/oauth-2-resource-owner-credentials-grant.md)
126
+ * [`OAuthBearerToken (OAuth 2 Bearer token)`](https://www.github.com/Syed-Subtain/multi-auth-project-ruby-sdk/tree/1.0.0/doc/$a/https://www.github.com/Syed-Subtain/multi-auth-project-ruby-sdk/tree/1.0.0/oauth-2-bearer-token.md)
127
+ * `CustomAuth (Custom Authentication)`
128
+
129
+ ## List of APIs
130
+
131
+ * [O Auth Authorization](https://www.github.com/Syed-Subtain/multi-auth-project-ruby-sdk/tree/1.0.0/doc/controllers/o-auth-authorization.md)
132
+ * [Authentication](https://www.github.com/Syed-Subtain/multi-auth-project-ruby-sdk/tree/1.0.0/doc/controllers/authentication.md)
133
+
134
+ ## Classes Documentation
135
+
136
+ * [Utility Classes](https://www.github.com/Syed-Subtain/multi-auth-project-ruby-sdk/tree/1.0.0/doc/utility-classes.md)
137
+ * [HttpResponse](https://www.github.com/Syed-Subtain/multi-auth-project-ruby-sdk/tree/1.0.0/doc/http-response.md)
138
+ * [HttpRequest](https://www.github.com/Syed-Subtain/multi-auth-project-ruby-sdk/tree/1.0.0/doc/http-request.md)
139
+
@@ -0,0 +1,10 @@
1
+ # multi_auth_sample
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module MultiAuthSample
7
+ # API utility class
8
+ class APIHelper < CoreLibrary::ApiHelper
9
+ end
10
+ end
@@ -0,0 +1,105 @@
1
+ # multi_auth_sample
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module MultiAuthSample
7
+ # multi_auth_sample client class.
8
+ class Client
9
+ attr_reader :config, :auth_managers
10
+
11
+ # Returns the configured authentication OAuthCCG instance.
12
+ def o_auth_ccg
13
+ @auth_managers['OAuthCCG']
14
+ end
15
+
16
+ # Returns the configured authentication OAuthACG instance.
17
+ def o_auth_acg
18
+ @auth_managers['OAuthACG']
19
+ end
20
+
21
+ # Returns the configured authentication OAuthROPCG instance.
22
+ def o_auth_ropcg
23
+ @auth_managers['OAuthROPCG']
24
+ end
25
+
26
+ # Access to authentication controller.
27
+ # @return [AuthenticationController] Returns the controller instance.
28
+ def authentication
29
+ @authentication ||= AuthenticationController.new @global_configuration
30
+ end
31
+
32
+ # Access to o_auth_authorization controller.
33
+ # @return [OAuthAuthorizationController] Returns the controller instance.
34
+ def o_auth_authorization
35
+ @o_auth_authorization ||= OAuthAuthorizationController.new @global_configuration
36
+ end
37
+
38
+ def initialize(
39
+ connection: nil, adapter: :net_http_persistent, timeout: 60,
40
+ max_retries: 0, retry_interval: 1, backoff_factor: 2,
41
+ retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
42
+ retry_methods: %i[get put], http_callback: nil,
43
+ environment: Environment::TESTING, port: '80',
44
+ suites: SuiteCodeEnum::HEARTS, basic_auth_credentials: nil,
45
+ api_key_credentials: nil, api_header_credentials: nil,
46
+ o_auth_ccg_credentials: nil, o_auth_acg_credentials: nil,
47
+ o_auth_ropcg_credentials: nil, o_auth_bearer_token_credentials: nil,
48
+ custom_auth_credentials: nil, access_token: '', config: nil
49
+ )
50
+ @config = if config.nil?
51
+ Configuration.new(
52
+ connection: connection, adapter: adapter, timeout: timeout,
53
+ max_retries: max_retries, retry_interval: retry_interval,
54
+ backoff_factor: backoff_factor,
55
+ retry_statuses: retry_statuses,
56
+ retry_methods: retry_methods, http_callback: http_callback,
57
+ environment: environment, port: port, suites: suites,
58
+ basic_auth_credentials: basic_auth_credentials,
59
+ api_key_credentials: api_key_credentials,
60
+ api_header_credentials: api_header_credentials,
61
+ o_auth_ccg_credentials: o_auth_ccg_credentials,
62
+ o_auth_acg_credentials: o_auth_acg_credentials,
63
+ o_auth_ropcg_credentials: o_auth_ropcg_credentials,
64
+ o_auth_bearer_token_credentials: o_auth_bearer_token_credentials,
65
+ custom_auth_credentials: custom_auth_credentials,
66
+ access_token: access_token
67
+ )
68
+ else
69
+ config
70
+ end
71
+
72
+ @global_configuration = GlobalConfiguration.new(client_configuration: @config)
73
+ .base_uri_executor(@config.method(:get_base_uri))
74
+ .global_errors(BaseController::GLOBAL_ERRORS)
75
+ .user_agent(BaseController.user_agent)
76
+ .global_header('accessToken', @config.access_token)
77
+
78
+ initialize_auth_managers(@global_configuration)
79
+ @global_configuration = @global_configuration.auth_managers(@auth_managers)
80
+ end
81
+
82
+ # Initializes the auth managers hash used for authenticating API calls.
83
+ # @param [GlobalConfiguration] global_config The global configuration of the SDK)
84
+ def initialize_auth_managers(global_config)
85
+ @auth_managers = {}
86
+ http_client_config = global_config.client_configuration
87
+ %w[basicAuth apiKey apiHeader OAuthCCG OAuthACG OAuthROPCG OAuthBearerToken CustomAuth].each do |auth|
88
+ @auth_managers[auth] = nil
89
+ end
90
+ @auth_managers['basicAuth'] = BasicAuth.new(http_client_config.basic_auth_credentials)
91
+ @auth_managers['apiKey'] = ApiKey.new(http_client_config.api_key_credentials)
92
+ @auth_managers['apiHeader'] = ApiHeader.new(http_client_config.api_header_credentials)
93
+ @auth_managers['OAuthCCG'] = OAuthCCG.new(http_client_config.o_auth_ccg_credentials,
94
+ global_config)
95
+ @auth_managers['OAuthACG'] = OAuthACG.new(http_client_config.o_auth_acg_credentials,
96
+ global_config)
97
+ @auth_managers['OAuthROPCG'] = OAuthROPCG.new(http_client_config.o_auth_ropcg_credentials,
98
+ global_config)
99
+ @auth_managers['OAuthBearerToken'] = OAuthBearerToken.new(
100
+ http_client_config.o_auth_bearer_token_credentials
101
+ )
102
+ @auth_managers['CustomAuth'] = CustomAuth.new(http_client_config)
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,170 @@
1
+ # multi_auth_sample
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module MultiAuthSample
7
+ # An enum for SDK environments.
8
+ class Environment
9
+ ENVIRONMENT = [
10
+ PRODUCTION = 'production'.freeze,
11
+ TESTING = 'testing'.freeze
12
+ ].freeze
13
+ end
14
+
15
+ # An enum for API servers.
16
+ class Server
17
+ SERVER = [
18
+ DEFAULT = 'default'.freeze,
19
+ AUTH = 'auth'.freeze
20
+ ].freeze
21
+ end
22
+
23
+ # All configuration including auth info and base URI for the API access
24
+ # are configured in this class.
25
+ class Configuration < CoreLibrary::HttpClientConfiguration
26
+ # The attribute readers for properties.
27
+ attr_reader :environment, :port, :suites, :basic_auth_credentials, :api_key_credentials,
28
+ :api_header_credentials, :o_auth_ccg_credentials, :o_auth_acg_credentials,
29
+ :o_auth_ropcg_credentials, :o_auth_bearer_token_credentials,
30
+ :custom_auth_credentials, :access_token
31
+
32
+ class << self
33
+ attr_reader :environments
34
+ end
35
+
36
+ def initialize(
37
+ connection: nil, adapter: :net_http_persistent, timeout: 60,
38
+ max_retries: 0, retry_interval: 1, backoff_factor: 2,
39
+ retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
40
+ retry_methods: %i[get put], http_callback: nil,
41
+ environment: Environment::TESTING, port: '80',
42
+ suites: SuiteCodeEnum::HEARTS, basic_auth_credentials: nil,
43
+ api_key_credentials: nil, api_header_credentials: nil,
44
+ o_auth_ccg_credentials: nil, o_auth_acg_credentials: nil,
45
+ o_auth_ropcg_credentials: nil, o_auth_bearer_token_credentials: nil,
46
+ custom_auth_credentials: nil, access_token: ''
47
+ )
48
+
49
+ super connection: connection, adapter: adapter, timeout: timeout,
50
+ max_retries: max_retries, retry_interval: retry_interval,
51
+ backoff_factor: backoff_factor, retry_statuses: retry_statuses,
52
+ retry_methods: retry_methods, http_callback: http_callback
53
+
54
+ # Current API environment
55
+ @environment = String(environment)
56
+
57
+ # port value
58
+ @port = port
59
+
60
+ # suites value
61
+ @suites = suites
62
+
63
+ # The object holding Basic Authentication credentials
64
+ @basic_auth_credentials = basic_auth_credentials
65
+
66
+ # The object holding Custom Query Parameter credentials
67
+ @api_key_credentials = api_key_credentials
68
+
69
+ # The object holding Custom Header Signature credentials
70
+ @api_header_credentials = api_header_credentials
71
+
72
+ # The object holding OAuth 2 Client Credentials Grant credentials
73
+ @o_auth_ccg_credentials = o_auth_ccg_credentials
74
+
75
+ # The object holding OAuth 2 Authorization Code Grant credentials
76
+ @o_auth_acg_credentials = o_auth_acg_credentials
77
+
78
+ # The object holding OAuth 2 Resource Owner Credentials Grant credentials
79
+ @o_auth_ropcg_credentials = o_auth_ropcg_credentials
80
+
81
+ # The object holding OAuth 2 Bearer token credentials
82
+ @o_auth_bearer_token_credentials = o_auth_bearer_token_credentials
83
+
84
+ # The object holding Custom Authentication credentials
85
+ @custom_auth_credentials = custom_auth_credentials
86
+
87
+ # TODO: Replace
88
+ @access_token = access_token
89
+
90
+ # The Http Client to use for making requests.
91
+ set_http_client CoreLibrary::FaradayClient.new(self)
92
+ end
93
+
94
+ def clone_with(connection: nil, adapter: nil, timeout: nil,
95
+ max_retries: nil, retry_interval: nil, backoff_factor: nil,
96
+ retry_statuses: nil, retry_methods: nil, http_callback: nil,
97
+ environment: nil, port: nil, suites: nil,
98
+ basic_auth_credentials: nil, api_key_credentials: nil,
99
+ api_header_credentials: nil, o_auth_ccg_credentials: nil,
100
+ o_auth_acg_credentials: nil, o_auth_ropcg_credentials: nil,
101
+ o_auth_bearer_token_credentials: nil,
102
+ custom_auth_credentials: nil, access_token: nil)
103
+ connection ||= self.connection
104
+ adapter ||= self.adapter
105
+ timeout ||= self.timeout
106
+ max_retries ||= self.max_retries
107
+ retry_interval ||= self.retry_interval
108
+ backoff_factor ||= self.backoff_factor
109
+ retry_statuses ||= self.retry_statuses
110
+ retry_methods ||= self.retry_methods
111
+ http_callback ||= self.http_callback
112
+ environment ||= self.environment
113
+ port ||= self.port
114
+ suites ||= self.suites
115
+ basic_auth_credentials ||= self.basic_auth_credentials
116
+ api_key_credentials ||= self.api_key_credentials
117
+ api_header_credentials ||= self.api_header_credentials
118
+ o_auth_ccg_credentials ||= self.o_auth_ccg_credentials
119
+ o_auth_acg_credentials ||= self.o_auth_acg_credentials
120
+ o_auth_ropcg_credentials ||= self.o_auth_ropcg_credentials
121
+ o_auth_bearer_token_credentials ||= self.o_auth_bearer_token_credentials
122
+ custom_auth_credentials ||= self.custom_auth_credentials
123
+ access_token ||= self.access_token
124
+
125
+ Configuration.new(
126
+ connection: connection, adapter: adapter, timeout: timeout,
127
+ max_retries: max_retries, retry_interval: retry_interval,
128
+ backoff_factor: backoff_factor, retry_statuses: retry_statuses,
129
+ retry_methods: retry_methods, http_callback: http_callback,
130
+ environment: environment, port: port, suites: suites,
131
+ basic_auth_credentials: basic_auth_credentials,
132
+ api_key_credentials: api_key_credentials,
133
+ api_header_credentials: api_header_credentials,
134
+ o_auth_ccg_credentials: o_auth_ccg_credentials,
135
+ o_auth_acg_credentials: o_auth_acg_credentials,
136
+ o_auth_ropcg_credentials: o_auth_ropcg_credentials,
137
+ o_auth_bearer_token_credentials: o_auth_bearer_token_credentials,
138
+ custom_auth_credentials: custom_auth_credentials,
139
+ access_token: access_token
140
+ )
141
+ end
142
+
143
+
144
+ # All the environments the SDK can run in.
145
+ ENVIRONMENTS = {
146
+ Environment::PRODUCTION => {
147
+ Server::DEFAULT => 'http://apimatic.hopto.org:{suites}',
148
+ Server::AUTH => 'http://apimaticauth.hopto.org:3000'
149
+ },
150
+ Environment::TESTING => {
151
+ Server::DEFAULT => 'http://localhost:3000',
152
+ Server::AUTH => 'http://localhost:3000/oauth2/auth-server'
153
+ }
154
+ }.freeze
155
+
156
+ # Generates the appropriate base URI for the environment and the server.
157
+ # @param [Configuration::Server] server The server enum for which the base URI is
158
+ # required.
159
+ # @return [String] The base URI.
160
+ def get_base_uri(server = Server::DEFAULT)
161
+ parameters = {
162
+ 'port' => { 'value' => port, 'encode' => false },
163
+ 'suites' => { 'value' => suites, 'encode' => false }
164
+ }
165
+ APIHelper.append_url_with_template_parameters(
166
+ ENVIRONMENTS[environment][server], parameters
167
+ )
168
+ end
169
+ end
170
+ end
@@ -0,0 +1,151 @@
1
+ # multi_auth_sample
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module MultiAuthSample
7
+ # AuthenticationController
8
+ class AuthenticationController < BaseController
9
+ # TODO: type endpoint description here
10
+ # @return [String] response from the API call
11
+ def o_auth_bearer_token
12
+ new_api_call_builder
13
+ .request(new_request_builder(HttpMethodEnum::GET,
14
+ '/auth/oauth2',
15
+ Server::DEFAULT)
16
+ .auth(Single.new('OAuthBearerToken')))
17
+ .response(new_response_handler
18
+ .deserializer(APIHelper.method(:deserialize_primitive_types))
19
+ .deserialize_into(proc do |response| response.to_s end)
20
+ .is_primitive_response(true))
21
+ .execute
22
+ end
23
+
24
+ # TODO: type endpoint description here
25
+ # @return [String] response from the API call
26
+ def custom_authentication
27
+ new_api_call_builder
28
+ .request(new_request_builder(HttpMethodEnum::GET,
29
+ '/auth/customAuthentication',
30
+ Server::DEFAULT)
31
+ .auth(Single.new('CustomAuth')))
32
+ .response(new_response_handler
33
+ .deserializer(APIHelper.method(:deserialize_primitive_types))
34
+ .deserialize_into(proc do |response| response.to_s end)
35
+ .is_primitive_response(true))
36
+ .execute
37
+ end
38
+
39
+ # TODO: type endpoint description here
40
+ # @return [String] response from the API call
41
+ def custom_query_or_header_authentication
42
+ new_api_call_builder
43
+ .request(new_request_builder(HttpMethodEnum::GET,
44
+ '/auth/customQueryOrHeaderParam',
45
+ Server::DEFAULT)
46
+ .auth(Or.new('apiKey', 'apiHeader')))
47
+ .response(new_response_handler
48
+ .deserializer(APIHelper.method(:deserialize_primitive_types))
49
+ .deserialize_into(proc do |response| response.to_s end)
50
+ .is_primitive_response(true))
51
+ .execute
52
+ end
53
+
54
+ # This endpoint tests or combinations of OAuth types
55
+ # @return [String] response from the API call
56
+ def o_auth_grant_types_or_combinations
57
+ new_api_call_builder
58
+ .request(new_request_builder(HttpMethodEnum::GET,
59
+ '/oauth2/oauthOrCombination',
60
+ Server::DEFAULT)
61
+ .auth(Or.new('OAuthCCG', 'OAuthBearerToken')))
62
+ .response(new_response_handler
63
+ .deserializer(APIHelper.method(:deserialize_primitive_types))
64
+ .deserialize_into(proc do |response| response.to_s end)
65
+ .is_primitive_response(true))
66
+ .execute
67
+ end
68
+
69
+ # This endpoint does not use auth.
70
+ # @return [String] response from the API call
71
+ def no_auth
72
+ warn 'Endpoint no_auth in AuthenticationController is deprecated since v'\
73
+ 'ersion 0.0.1-alpha. You should not use this method as it requir'\
74
+ 'es no auth and can bring security issues to the server and api cal'\
75
+ 'l itself!!'
76
+ new_api_call_builder
77
+ .request(new_request_builder(HttpMethodEnum::GET,
78
+ '/auth/noAuth',
79
+ Server::DEFAULT)
80
+ .query_param(new_parameter(true, key: 'array')))
81
+ .response(new_response_handler
82
+ .deserializer(APIHelper.method(:deserialize_primitive_types))
83
+ .deserialize_into(proc do |response| response.to_s end)
84
+ .is_primitive_response(true))
85
+ .execute
86
+ end
87
+
88
+ # TODO: type endpoint description here
89
+ # @return [ServiceStatus] response from the API call
90
+ def o_auth_client_credentials_grant
91
+ new_api_call_builder
92
+ .request(new_request_builder(HttpMethodEnum::GET,
93
+ '/oauth2/non-auth-server/status',
94
+ Server::DEFAULT)
95
+ .header_param(new_parameter('application/json', key: 'accept'))
96
+ .auth(Single.new('OAuthCCG')))
97
+ .response(new_response_handler
98
+ .deserializer(APIHelper.method(:custom_type_deserializer))
99
+ .deserialize_into(ServiceStatus.method(:from_hash)))
100
+ .execute
101
+ end
102
+
103
+ # TODO: type endpoint description here
104
+ # @return [String] response from the API call
105
+ def basic_auth_and_api_header_auth
106
+ new_api_call_builder
107
+ .request(new_request_builder(HttpMethodEnum::GET,
108
+ '/auth/basicAndApiKeyAndApiHeader',
109
+ Server::DEFAULT)
110
+ .auth(And.new('basicAuth', 'apiKey', 'apiHeader')))
111
+ .response(new_response_handler
112
+ .deserializer(APIHelper.method(:deserialize_primitive_types))
113
+ .deserialize_into(proc do |response| response.to_s end)
114
+ .is_primitive_response(true))
115
+ .execute
116
+ end
117
+
118
+ # TODO: type endpoint description here
119
+ # @return [User] response from the API call
120
+ def o_auth_authorization_grant
121
+ new_api_call_builder
122
+ .request(new_request_builder(HttpMethodEnum::GET,
123
+ '/oauth2/non-auth-server/user',
124
+ Server::DEFAULT)
125
+ .header_param(new_parameter('application/json', key: 'accept'))
126
+ .auth(And.new('OAuthACG', 'OAuthROPCG')))
127
+ .response(new_response_handler
128
+ .deserializer(APIHelper.method(:custom_type_deserializer))
129
+ .deserialize_into(User.method(:from_hash)))
130
+ .execute
131
+ end
132
+
133
+ # This endpoint uses globally applied auth which is a hypothetical scneraio
134
+ # but covers the worst case.
135
+ # @return [String] response from the API call
136
+ def multiple_auth_combination
137
+ warn 'Endpoint multiple_auth_combination in AuthenticationController is '\
138
+ 'deprecated'
139
+ new_api_call_builder
140
+ .request(new_request_builder(HttpMethodEnum::GET,
141
+ '/auth/multipleAuthCombination',
142
+ Server::DEFAULT)
143
+ .auth(Or.new('CustomAuth', 'OAuthBearerToken', And.new('basicAuth', 'apiKey', 'apiHeader'))))
144
+ .response(new_response_handler
145
+ .deserializer(APIHelper.method(:deserialize_primitive_types))
146
+ .deserialize_into(proc do |response| response.to_s end)
147
+ .is_primitive_response(true))
148
+ .execute
149
+ end
150
+ end
151
+ end