authress-sdk 0.1.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +7 -0
  2. data/lib/swagger_client.rb +30 -0
  3. data/lib/swagger_client/api/access_records_api.rb +541 -0
  4. data/lib/swagger_client/api/accounts_api.rb +232 -0
  5. data/lib/swagger_client/api/metadata_api.rb +152 -0
  6. data/lib/swagger_client/api/resource_permissions_api.rb +250 -0
  7. data/lib/swagger_client/api/roles_api.rb +252 -0
  8. data/lib/swagger_client/api/service_clients_api.rb +418 -0
  9. data/lib/swagger_client/api/user_permissions_api.rb +340 -0
  10. data/lib/swagger_client/api_client.rb +388 -0
  11. data/lib/swagger_client/api_error.rb +57 -0
  12. data/lib/swagger_client/configuration.rb +205 -0
  13. data/lib/swagger_client/models/access_record.rb +351 -0
  14. data/lib/swagger_client/models/access_record_collection.rb +229 -0
  15. data/lib/swagger_client/models/access_record_collection_records.rb +351 -0
  16. data/lib/swagger_client/models/account.rb +268 -0
  17. data/lib/swagger_client/models/account_collection.rb +211 -0
  18. data/lib/swagger_client/models/account_collection_accounts.rb +268 -0
  19. data/lib/swagger_client/models/body.rb +236 -0
  20. data/lib/swagger_client/models/body_1.rb +229 -0
  21. data/lib/swagger_client/models/body_10.rb +246 -0
  22. data/lib/swagger_client/models/body_11.rb +246 -0
  23. data/lib/swagger_client/models/body_2.rb +213 -0
  24. data/lib/swagger_client/models/body_3.rb +351 -0
  25. data/lib/swagger_client/models/body_4.rb +351 -0
  26. data/lib/swagger_client/models/body_5.rb +225 -0
  27. data/lib/swagger_client/models/body_6.rb +255 -0
  28. data/lib/swagger_client/models/body_7.rb +255 -0
  29. data/lib/swagger_client/models/body_8.rb +227 -0
  30. data/lib/swagger_client/models/body_9.rb +223 -0
  31. data/lib/swagger_client/models/claim_request.rb +227 -0
  32. data/lib/swagger_client/models/claim_response.rb +197 -0
  33. data/lib/swagger_client/models/client.rb +246 -0
  34. data/lib/swagger_client/models/client_access_key.rb +242 -0
  35. data/lib/swagger_client/models/client_collection.rb +229 -0
  36. data/lib/swagger_client/models/client_collection_clients.rb +246 -0
  37. data/lib/swagger_client/models/identity.rb +228 -0
  38. data/lib/swagger_client/models/identity_collection.rb +213 -0
  39. data/lib/swagger_client/models/identity_collection_identities.rb +228 -0
  40. data/lib/swagger_client/models/identity_request.rb +223 -0
  41. data/lib/swagger_client/models/inline_response_200.rb +247 -0
  42. data/lib/swagger_client/models/inline_response_200_1.rb +236 -0
  43. data/lib/swagger_client/models/inline_response_200_10.rb +255 -0
  44. data/lib/swagger_client/models/inline_response_200_11.rb +211 -0
  45. data/lib/swagger_client/models/inline_response_200_12.rb +213 -0
  46. data/lib/swagger_client/models/inline_response_200_13.rb +229 -0
  47. data/lib/swagger_client/models/inline_response_200_14.rb +246 -0
  48. data/lib/swagger_client/models/inline_response_200_15.rb +242 -0
  49. data/lib/swagger_client/models/inline_response_200_2.rb +238 -0
  50. data/lib/swagger_client/models/inline_response_200_3.rb +260 -0
  51. data/lib/swagger_client/models/inline_response_200_4.rb +228 -0
  52. data/lib/swagger_client/models/inline_response_200_5.rb +213 -0
  53. data/lib/swagger_client/models/inline_response_200_6.rb +229 -0
  54. data/lib/swagger_client/models/inline_response_200_7.rb +229 -0
  55. data/lib/swagger_client/models/inline_response_200_8.rb +351 -0
  56. data/lib/swagger_client/models/inline_response_200_9.rb +268 -0
  57. data/lib/swagger_client/models/invite.rb +225 -0
  58. data/lib/swagger_client/models/link.rb +223 -0
  59. data/lib/swagger_client/models/metadata_object.rb +236 -0
  60. data/lib/swagger_client/models/permission_object.rb +258 -0
  61. data/lib/swagger_client/models/permission_response.rb +238 -0
  62. data/lib/swagger_client/models/resource_permission.rb +213 -0
  63. data/lib/swagger_client/models/resource_permission_collection.rb +228 -0
  64. data/lib/swagger_client/models/resource_permission_collection_links.rb +220 -0
  65. data/lib/swagger_client/models/resource_permission_collection_links_next.rb +223 -0
  66. data/lib/swagger_client/models/resource_permission_collection_resources.rb +213 -0
  67. data/lib/swagger_client/models/resource_users_collection.rb +229 -0
  68. data/lib/swagger_client/models/role.rb +255 -0
  69. data/lib/swagger_client/models/statement.rb +229 -0
  70. data/lib/swagger_client/models/token_request.rb +229 -0
  71. data/lib/swagger_client/models/user.rb +212 -0
  72. data/lib/swagger_client/models/user_resources.rb +247 -0
  73. data/lib/swagger_client/models/user_resources_resources.rb +207 -0
  74. data/lib/swagger_client/models/user_token.rb +260 -0
  75. data/lib/swagger_client/models/user_token_links.rb +211 -0
  76. data/lib/swagger_client/models/user_token_links_self.rb +223 -0
  77. data/lib/swagger_client/models/v1clients_options.rb +218 -0
  78. data/lib/swagger_client/models/v1records_account.rb +211 -0
  79. data/lib/swagger_client/models/v1records_links.rb +211 -0
  80. data/lib/swagger_client/models/v1records_links_self.rb +223 -0
  81. data/lib/swagger_client/models/v1records_users.rb +212 -0
  82. data/lib/swagger_client/models/v1resourcesresource_uri_permissions.rb +259 -0
  83. data/lib/swagger_client/models/v1roles_permissions.rb +258 -0
  84. data/lib/swagger_client/models/v1usersuser_idresourcesresource_urimetadata_account.rb +206 -0
  85. data/lib/swagger_client/models/v1usersuser_idtokens_resources.rb +212 -0
  86. data/lib/swagger_client/models/v1usersuser_idtokens_statements.rb +229 -0
  87. data/lib/swagger_client/version.rb +14 -0
  88. metadata +313 -0
@@ -0,0 +1,340 @@
1
+ =begin
2
+ #Authress
3
+
4
+ #<p> <h2>Authorization</h2> <p>Authorization for Authress is handled one of two different ways. Both mechanisms use oauth2 <i>Bearer</i> tokens.</p> <br> <h4>Identity Provider JWT</h4> <p>Hook up your preferred identity provider directly to Authress. Authress will verify JWTs sourced from that identify provider and allow direct integration with these APIs. Any OIDC JWT provider works, Google, Auth0, Okta, etc... With this mechanism your web app can make direct calls to the permissions API on behalf of your users. <br> <a href=\"https://authress.io/app/#/manage?focus=identity\">Link identity provider</a> </p> <br> <h4>Authress Clients</h4> <p>Regardless of using direct identity provider integration, with the API you can create Authress clients which can call any of the methods on the API. Your users won't be able to directly make API calls, all web app integrations must go through a service which stores the Authress private key. <br> <a href=\"https://authress.io/app/#/manage?focus=clients\">Create Authress service client</a> </p> <br> <h2>Usage</h2> <h4>Billable APIs</h4> <p>Most of the api available is completely free. Use it to populate your roles and configure your account. You'll only be charged for the ones marked as Billable.</p> <p><ul> <li><i class=\"far fa-fw fa-money-bill-alt text-primary\"></i> <span class=\"text-primary\">Billable</span> - <small>These APIs count as calls for your account and will be charged.</small></li> <li><i class=\"fas fa-fw fa-angle-double-right text-secondary\"></i> <span class=\"text-secondary\">Free</span> - <small>These are totally free.</small></li> <li><i class=\"fas fa-fw fa-balance-scale text-secondary\"></i> <span class=\"text-secondary\">Condition</span> - <small>Are conditionally free, see api methods for details.</small></li> </ul></p> <br> <h4>API Access</h4> <p>Access to the following APIs is based on Authress permissions, not the application permissions assigned in Authress to the application services. Each resource is tagged with the required permission <span class=\"badge badge-outline-secondary\">Action: Resource</span> </p>
5
+
6
+ OpenAPI spec version: v1
7
+ Contact: support@authress.io
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+ Swagger Codegen version: 3.0.23
10
+ =end
11
+
12
+ module SwaggerClient
13
+ class UserPermissionsApi
14
+ attr_accessor :api_client
15
+
16
+ def initialize(api_client = ApiClient.default)
17
+ @api_client = api_client
18
+ end
19
+ # Check to see if a user has permissions to a resource.
20
+ # <i class=\"far fa-money-bill-alt text-primary\"></i> <span class=\"text-primary\">Billable</span> Does the user have the specified permissions to the resource? <br><span class=\"badge badge-outline-secondary\">READ: Authress:UserPermissions/{userId}</span>
21
+ # @param user_id The user to check permissions on
22
+ # @param resource_uri The uri path of a resource to validate, must be URL encoded, uri segments are allowed, the resource must be a full path, and permissions are not inherited by sub-resources.
23
+ # @param permission Permission to check, &#x27;*&#x27; and scoped permissions can also be checked here.
24
+ # @param [Hash] opts the optional parameters
25
+ # @return [nil]
26
+ def authorize_user(user_id, resource_uri, permission, opts = {})
27
+ authorize_user_with_http_info(user_id, resource_uri, permission, opts)
28
+ nil
29
+ end
30
+
31
+ # Check to see if a user has permissions to a resource.
32
+ # &lt;i class&#x3D;\&quot;far fa-money-bill-alt text-primary\&quot;&gt;&lt;/i&gt; &lt;span class&#x3D;\&quot;text-primary\&quot;&gt;Billable&lt;/span&gt; Does the user have the specified permissions to the resource? &lt;br&gt;&lt;span class&#x3D;\&quot;badge badge-outline-secondary\&quot;&gt;READ: Authress:UserPermissions/{userId}&lt;/span&gt;
33
+ # @param user_id The user to check permissions on
34
+ # @param resource_uri The uri path of a resource to validate, must be URL encoded, uri segments are allowed, the resource must be a full path, and permissions are not inherited by sub-resources.
35
+ # @param permission Permission to check, &#x27;*&#x27; and scoped permissions can also be checked here.
36
+ # @param [Hash] opts the optional parameters
37
+ # @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers
38
+ def authorize_user_with_http_info(user_id, resource_uri, permission, opts = {})
39
+ if @api_client.config.debugging
40
+ @api_client.config.logger.debug 'Calling API: UserPermissionsApi.authorize_user ...'
41
+ end
42
+ # verify the required parameter 'user_id' is set
43
+ if @api_client.config.client_side_validation && user_id.nil?
44
+ fail ArgumentError, "Missing the required parameter 'user_id' when calling UserPermissionsApi.authorize_user"
45
+ end
46
+ # verify the required parameter 'resource_uri' is set
47
+ if @api_client.config.client_side_validation && resource_uri.nil?
48
+ fail ArgumentError, "Missing the required parameter 'resource_uri' when calling UserPermissionsApi.authorize_user"
49
+ end
50
+ # verify the required parameter 'permission' is set
51
+ if @api_client.config.client_side_validation && permission.nil?
52
+ fail ArgumentError, "Missing the required parameter 'permission' when calling UserPermissionsApi.authorize_user"
53
+ end
54
+ # resource path
55
+ local_var_path = '/v1/users/{userId}/resources/{resourceUri}/permissions/{permission}'.sub('{' + 'userId' + '}', user_id.to_s).sub('{' + 'resourceUri' + '}', resource_uri.to_s).sub('{' + 'permission' + '}', permission.to_s)
56
+
57
+ # query parameters
58
+ query_params = opts[:query_params] || {}
59
+
60
+ # header parameters
61
+ header_params = opts[:header_params] || {}
62
+
63
+ # form parameters
64
+ form_params = opts[:form_params] || {}
65
+
66
+ # http body (model)
67
+ post_body = opts[:body]
68
+
69
+ return_type = opts[:return_type]
70
+
71
+ auth_names = opts[:auth_names] || ['oauth2']
72
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path,
73
+ :header_params => header_params,
74
+ :query_params => query_params,
75
+ :form_params => form_params,
76
+ :body => post_body,
77
+ :auth_names => auth_names,
78
+ :return_type => return_type)
79
+
80
+ if @api_client.config.debugging
81
+ @api_client.config.logger.debug "API called: UserPermissionsApi#authorize_user\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
82
+ end
83
+ return data, status_code, headers
84
+ end
85
+ # Disable a token.
86
+ # <i class=\"far fa-money-bill-alt text-primary\"></i> <span class=\"text-primary\">Billable</span> Permanently disable a token. To be used after the token has completed its use. Should be called on all tokens to ensure they are not active indefinitely. <br><span class=\"badge badge-outline-secondary\">CONTACT: AuthressSupport</span>
87
+ # @param user_id The user to create an impersonation token for.
88
+ # @param token_id The relevant token identifier
89
+ # @param [Hash] opts the optional parameters
90
+ # @return [nil]
91
+ def disable_user_token(user_id, token_id, opts = {})
92
+ disable_user_token_with_http_info(user_id, token_id, opts)
93
+ nil
94
+ end
95
+
96
+ # Disable a token.
97
+ # &lt;i class&#x3D;\&quot;far fa-money-bill-alt text-primary\&quot;&gt;&lt;/i&gt; &lt;span class&#x3D;\&quot;text-primary\&quot;&gt;Billable&lt;/span&gt; Permanently disable a token. To be used after the token has completed its use. Should be called on all tokens to ensure they are not active indefinitely. &lt;br&gt;&lt;span class&#x3D;\&quot;badge badge-outline-secondary\&quot;&gt;CONTACT: AuthressSupport&lt;/span&gt;
98
+ # @param user_id The user to create an impersonation token for.
99
+ # @param token_id The relevant token identifier
100
+ # @param [Hash] opts the optional parameters
101
+ # @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers
102
+ def disable_user_token_with_http_info(user_id, token_id, opts = {})
103
+ if @api_client.config.debugging
104
+ @api_client.config.logger.debug 'Calling API: UserPermissionsApi.disable_user_token ...'
105
+ end
106
+ # verify the required parameter 'user_id' is set
107
+ if @api_client.config.client_side_validation && user_id.nil?
108
+ fail ArgumentError, "Missing the required parameter 'user_id' when calling UserPermissionsApi.disable_user_token"
109
+ end
110
+ # verify the required parameter 'token_id' is set
111
+ if @api_client.config.client_side_validation && token_id.nil?
112
+ fail ArgumentError, "Missing the required parameter 'token_id' when calling UserPermissionsApi.disable_user_token"
113
+ end
114
+ # resource path
115
+ local_var_path = '/v1/users/{userId}/tokens/{tokenId}'.sub('{' + 'userId' + '}', user_id.to_s).sub('{' + 'tokenId' + '}', token_id.to_s)
116
+
117
+ # query parameters
118
+ query_params = opts[:query_params] || {}
119
+
120
+ # header parameters
121
+ header_params = opts[:header_params] || {}
122
+
123
+ # form parameters
124
+ form_params = opts[:form_params] || {}
125
+
126
+ # http body (model)
127
+ post_body = opts[:body]
128
+
129
+ return_type = opts[:return_type]
130
+
131
+ auth_names = opts[:auth_names] || ['oauth2']
132
+ data, status_code, headers = @api_client.call_api(:DELETE, local_var_path,
133
+ :header_params => header_params,
134
+ :query_params => query_params,
135
+ :form_params => form_params,
136
+ :body => post_body,
137
+ :auth_names => auth_names,
138
+ :return_type => return_type)
139
+
140
+ if @api_client.config.debugging
141
+ @api_client.config.logger.debug "API called: UserPermissionsApi#disable_user_token\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
142
+ end
143
+ return data, status_code, headers
144
+ end
145
+ # Get the permissions a user has to a resource.
146
+ # <i class=\"far fa-money-bill-alt text-primary\"></i> <span class=\"text-primary\">Billable</span> Get a summary of the permissions a user has to a particular resource. <br><span class=\"badge badge-outline-secondary\">READ: Authress:UserPermissions/{userId}</span>
147
+ # @param user_id The user to check permissions on
148
+ # @param resource_uri The uri path of a resource to validate, must be URL encoded, uri segments are allowed.
149
+ # @param [Hash] opts the optional parameters
150
+ # @return [InlineResponse2002]
151
+ def get_user_permissions_for_resource(user_id, resource_uri, opts = {})
152
+ data, _status_code, _headers = get_user_permissions_for_resource_with_http_info(user_id, resource_uri, opts)
153
+ data
154
+ end
155
+
156
+ # Get the permissions a user has to a resource.
157
+ # &lt;i class&#x3D;\&quot;far fa-money-bill-alt text-primary\&quot;&gt;&lt;/i&gt; &lt;span class&#x3D;\&quot;text-primary\&quot;&gt;Billable&lt;/span&gt; Get a summary of the permissions a user has to a particular resource. &lt;br&gt;&lt;span class&#x3D;\&quot;badge badge-outline-secondary\&quot;&gt;READ: Authress:UserPermissions/{userId}&lt;/span&gt;
158
+ # @param user_id The user to check permissions on
159
+ # @param resource_uri The uri path of a resource to validate, must be URL encoded, uri segments are allowed.
160
+ # @param [Hash] opts the optional parameters
161
+ # @return [Array<(InlineResponse2002, Integer, Hash)>] InlineResponse2002 data, response status code and response headers
162
+ def get_user_permissions_for_resource_with_http_info(user_id, resource_uri, opts = {})
163
+ if @api_client.config.debugging
164
+ @api_client.config.logger.debug 'Calling API: UserPermissionsApi.get_user_permissions_for_resource ...'
165
+ end
166
+ # verify the required parameter 'user_id' is set
167
+ if @api_client.config.client_side_validation && user_id.nil?
168
+ fail ArgumentError, "Missing the required parameter 'user_id' when calling UserPermissionsApi.get_user_permissions_for_resource"
169
+ end
170
+ # verify the required parameter 'resource_uri' is set
171
+ if @api_client.config.client_side_validation && resource_uri.nil?
172
+ fail ArgumentError, "Missing the required parameter 'resource_uri' when calling UserPermissionsApi.get_user_permissions_for_resource"
173
+ end
174
+ # resource path
175
+ local_var_path = '/v1/users/{userId}/resources/{resourceUri}/permissions'.sub('{' + 'userId' + '}', user_id.to_s).sub('{' + 'resourceUri' + '}', resource_uri.to_s)
176
+
177
+ # query parameters
178
+ query_params = opts[:query_params] || {}
179
+
180
+ # header parameters
181
+ header_params = opts[:header_params] || {}
182
+ # HTTP header 'Accept' (if needed)
183
+ header_params['Accept'] = @api_client.select_header_accept(['application/links+json'])
184
+
185
+ # form parameters
186
+ form_params = opts[:form_params] || {}
187
+
188
+ # http body (model)
189
+ post_body = opts[:body]
190
+
191
+ return_type = opts[:return_type] || 'InlineResponse2002'
192
+
193
+ auth_names = opts[:auth_names] || ['oauth2']
194
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path,
195
+ :header_params => header_params,
196
+ :query_params => query_params,
197
+ :form_params => form_params,
198
+ :body => post_body,
199
+ :auth_names => auth_names,
200
+ :return_type => return_type)
201
+
202
+ if @api_client.config.debugging
203
+ @api_client.config.logger.debug "API called: UserPermissionsApi#get_user_permissions_for_resource\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
204
+ end
205
+ return data, status_code, headers
206
+ end
207
+ # Get the resources a user has to permission to.
208
+ # <i class=\"far fa-money-bill-alt text-primary\"></i> <span class=\"text-primary\">Billable</span> Get the users resources. This result is a list of resource uris that a user has an explicit permission to, a user with * access to all sub resources will return an empty list. To get a user's list of resources in this cases, it is recommended to also check explicit access to the collection resource, using the <strong>authorizeUser</strong> endpoint. In the case that the user only has access to a subset of resources in a collection, the list will be paginated. <br><span class=\"badge badge-outline-secondary\">READ: Authress:UserPermissions/{userId}</span>
209
+ # @param user_id The user to check permissions on
210
+ # @param [Hash] opts the optional parameters
211
+ # @option opts [String] :resource_uri The top level uri path of a resource to query for. Will only match explicit or collection resource children. Will not partial match resource names. (default to *)
212
+ # @option opts [String] :permissions Permission to check, &#x27;*&#x27; and scoped permissions can also be checked here. By default if the user has any permission explicitly to a resource, it will be included in the list.
213
+ # @option opts [Integer] :limit Max number of results to return (default to 20)
214
+ # @option opts [String] :cursor Continuation cursor for paging (will automatically be set)
215
+ # @return [InlineResponse200]
216
+ def get_user_resources(user_id, opts = {})
217
+ data, _status_code, _headers = get_user_resources_with_http_info(user_id, opts)
218
+ data
219
+ end
220
+
221
+ # Get the resources a user has to permission to.
222
+ # &lt;i class&#x3D;\&quot;far fa-money-bill-alt text-primary\&quot;&gt;&lt;/i&gt; &lt;span class&#x3D;\&quot;text-primary\&quot;&gt;Billable&lt;/span&gt; Get the users resources. This result is a list of resource uris that a user has an explicit permission to, a user with * access to all sub resources will return an empty list. To get a user&#x27;s list of resources in this cases, it is recommended to also check explicit access to the collection resource, using the &lt;strong&gt;authorizeUser&lt;/strong&gt; endpoint. In the case that the user only has access to a subset of resources in a collection, the list will be paginated. &lt;br&gt;&lt;span class&#x3D;\&quot;badge badge-outline-secondary\&quot;&gt;READ: Authress:UserPermissions/{userId}&lt;/span&gt;
223
+ # @param user_id The user to check permissions on
224
+ # @param [Hash] opts the optional parameters
225
+ # @option opts [String] :resource_uri The top level uri path of a resource to query for. Will only match explicit or collection resource children. Will not partial match resource names.
226
+ # @option opts [String] :permissions Permission to check, &#x27;*&#x27; and scoped permissions can also be checked here. By default if the user has any permission explicitly to a resource, it will be included in the list.
227
+ # @option opts [Integer] :limit Max number of results to return
228
+ # @option opts [String] :cursor Continuation cursor for paging (will automatically be set)
229
+ # @return [Array<(InlineResponse200, Integer, Hash)>] InlineResponse200 data, response status code and response headers
230
+ def get_user_resources_with_http_info(user_id, opts = {})
231
+ if @api_client.config.debugging
232
+ @api_client.config.logger.debug 'Calling API: UserPermissionsApi.get_user_resources ...'
233
+ end
234
+ # verify the required parameter 'user_id' is set
235
+ if @api_client.config.client_side_validation && user_id.nil?
236
+ fail ArgumentError, "Missing the required parameter 'user_id' when calling UserPermissionsApi.get_user_resources"
237
+ end
238
+ # resource path
239
+ local_var_path = '/v1/users/{userId}/resources'.sub('{' + 'userId' + '}', user_id.to_s)
240
+
241
+ # query parameters
242
+ query_params = opts[:query_params] || {}
243
+ query_params[:'resourceUri'] = opts[:'resource_uri'] if !opts[:'resource_uri'].nil?
244
+ query_params[:'permissions'] = opts[:'permissions'] if !opts[:'permissions'].nil?
245
+ query_params[:'limit'] = opts[:'limit'] if !opts[:'limit'].nil?
246
+ query_params[:'cursor'] = opts[:'cursor'] if !opts[:'cursor'].nil?
247
+
248
+ # header parameters
249
+ header_params = opts[:header_params] || {}
250
+ # HTTP header 'Accept' (if needed)
251
+ header_params['Accept'] = @api_client.select_header_accept(['application/links+json'])
252
+
253
+ # form parameters
254
+ form_params = opts[:form_params] || {}
255
+
256
+ # http body (model)
257
+ post_body = opts[:body]
258
+
259
+ return_type = opts[:return_type] || 'InlineResponse200'
260
+
261
+ auth_names = opts[:auth_names] || ['oauth2']
262
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path,
263
+ :header_params => header_params,
264
+ :query_params => query_params,
265
+ :form_params => form_params,
266
+ :body => post_body,
267
+ :auth_names => auth_names,
268
+ :return_type => return_type)
269
+
270
+ if @api_client.config.debugging
271
+ @api_client.config.logger.debug "API called: UserPermissionsApi#get_user_resources\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
272
+ end
273
+ return data, status_code, headers
274
+ end
275
+ # Request a user token with additional configuration.
276
+ # <i class=\"far fa-money-bill-alt text-primary\"></i> <span class=\"text-primary\">Billable</span> Get an Authress signed JWT access token using with userId as the sub. Additionally, can be configured to limit the permissions for this particular token and the length of time the token is valid. Token validation is real-time, so deleted tokens are restricted from being used as soon as they are deleted. This gives full control to the user and client creating the token. Client must have access to impersonating the user in order to generate tokens on their behalf. <br><span class=\"badge badge-outline-secondary\">CONTACT: AuthressSupport</span>
277
+ # @param body The contents of the permission to set on the token. Will be used instead of the users or clients full permissions. Cannot include permissions that the user or client do not have.
278
+ # @param user_id The user to create an impersonation token for.
279
+ # @param [Hash] opts the optional parameters
280
+ # @return [InlineResponse2003]
281
+ def request_user_token(body, user_id, opts = {})
282
+ data, _status_code, _headers = request_user_token_with_http_info(body, user_id, opts)
283
+ data
284
+ end
285
+
286
+ # Request a user token with additional configuration.
287
+ # &lt;i class&#x3D;\&quot;far fa-money-bill-alt text-primary\&quot;&gt;&lt;/i&gt; &lt;span class&#x3D;\&quot;text-primary\&quot;&gt;Billable&lt;/span&gt; Get an Authress signed JWT access token using with userId as the sub. Additionally, can be configured to limit the permissions for this particular token and the length of time the token is valid. Token validation is real-time, so deleted tokens are restricted from being used as soon as they are deleted. This gives full control to the user and client creating the token. Client must have access to impersonating the user in order to generate tokens on their behalf. &lt;br&gt;&lt;span class&#x3D;\&quot;badge badge-outline-secondary\&quot;&gt;CONTACT: AuthressSupport&lt;/span&gt;
288
+ # @param body The contents of the permission to set on the token. Will be used instead of the users or clients full permissions. Cannot include permissions that the user or client do not have.
289
+ # @param user_id The user to create an impersonation token for.
290
+ # @param [Hash] opts the optional parameters
291
+ # @return [Array<(InlineResponse2003, Integer, Hash)>] InlineResponse2003 data, response status code and response headers
292
+ def request_user_token_with_http_info(body, user_id, opts = {})
293
+ if @api_client.config.debugging
294
+ @api_client.config.logger.debug 'Calling API: UserPermissionsApi.request_user_token ...'
295
+ end
296
+ # verify the required parameter 'body' is set
297
+ if @api_client.config.client_side_validation && body.nil?
298
+ fail ArgumentError, "Missing the required parameter 'body' when calling UserPermissionsApi.request_user_token"
299
+ end
300
+ # verify the required parameter 'user_id' is set
301
+ if @api_client.config.client_side_validation && user_id.nil?
302
+ fail ArgumentError, "Missing the required parameter 'user_id' when calling UserPermissionsApi.request_user_token"
303
+ end
304
+ # resource path
305
+ local_var_path = '/v1/users/{userId}/tokens'.sub('{' + 'userId' + '}', user_id.to_s)
306
+
307
+ # query parameters
308
+ query_params = opts[:query_params] || {}
309
+
310
+ # header parameters
311
+ header_params = opts[:header_params] || {}
312
+ # HTTP header 'Accept' (if needed)
313
+ header_params['Accept'] = @api_client.select_header_accept(['application/links+json'])
314
+ # HTTP header 'Content-Type'
315
+ header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])
316
+
317
+ # form parameters
318
+ form_params = opts[:form_params] || {}
319
+
320
+ # http body (model)
321
+ post_body = opts[:body] || @api_client.object_to_http_body(body)
322
+
323
+ return_type = opts[:return_type] || 'InlineResponse2003'
324
+
325
+ auth_names = opts[:auth_names] || ['oauth2']
326
+ data, status_code, headers = @api_client.call_api(:POST, local_var_path,
327
+ :header_params => header_params,
328
+ :query_params => query_params,
329
+ :form_params => form_params,
330
+ :body => post_body,
331
+ :auth_names => auth_names,
332
+ :return_type => return_type)
333
+
334
+ if @api_client.config.debugging
335
+ @api_client.config.logger.debug "API called: UserPermissionsApi#request_user_token\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
336
+ end
337
+ return data, status_code, headers
338
+ end
339
+ end
340
+ end
@@ -0,0 +1,388 @@
1
+ =begin
2
+ #Authress
3
+
4
+ #<p> <h2>Authorization</h2> <p>Authorization for Authress is handled one of two different ways. Both mechanisms use oauth2 <i>Bearer</i> tokens.</p> <br> <h4>Identity Provider JWT</h4> <p>Hook up your preferred identity provider directly to Authress. Authress will verify JWTs sourced from that identify provider and allow direct integration with these APIs. Any OIDC JWT provider works, Google, Auth0, Okta, etc... With this mechanism your web app can make direct calls to the permissions API on behalf of your users. <br> <a href=\"https://authress.io/app/#/manage?focus=identity\">Link identity provider</a> </p> <br> <h4>Authress Clients</h4> <p>Regardless of using direct identity provider integration, with the API you can create Authress clients which can call any of the methods on the API. Your users won't be able to directly make API calls, all web app integrations must go through a service which stores the Authress private key. <br> <a href=\"https://authress.io/app/#/manage?focus=clients\">Create Authress service client</a> </p> <br> <h2>Usage</h2> <h4>Billable APIs</h4> <p>Most of the api available is completely free. Use it to populate your roles and configure your account. You'll only be charged for the ones marked as Billable.</p> <p><ul> <li><i class=\"far fa-fw fa-money-bill-alt text-primary\"></i> <span class=\"text-primary\">Billable</span> - <small>These APIs count as calls for your account and will be charged.</small></li> <li><i class=\"fas fa-fw fa-angle-double-right text-secondary\"></i> <span class=\"text-secondary\">Free</span> - <small>These are totally free.</small></li> <li><i class=\"fas fa-fw fa-balance-scale text-secondary\"></i> <span class=\"text-secondary\">Condition</span> - <small>Are conditionally free, see api methods for details.</small></li> </ul></p> <br> <h4>API Access</h4> <p>Access to the following APIs is based on Authress permissions, not the application permissions assigned in Authress to the application services. Each resource is tagged with the required permission <span class=\"badge badge-outline-secondary\">Action: Resource</span> </p>
5
+
6
+ OpenAPI spec version: v1
7
+ Contact: support@authress.io
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+ Swagger Codegen version: 3.0.23
10
+ =end
11
+
12
+ require 'date'
13
+ require 'json'
14
+ require 'logger'
15
+ require 'tempfile'
16
+ require 'typhoeus'
17
+ require 'uri'
18
+
19
+ module SwaggerClient
20
+ class ApiClient
21
+ # The Configuration object holding settings to be used in the API client.
22
+ attr_accessor :config
23
+
24
+ # Defines the headers to be used in HTTP requests of all API calls by default.
25
+ #
26
+ # @return [Hash]
27
+ attr_accessor :default_headers
28
+
29
+ # Initializes the ApiClient
30
+ # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
31
+ def initialize(config = Configuration.default)
32
+ @config = config
33
+ @user_agent = "Swagger-Codegen/#{VERSION}/ruby"
34
+ @default_headers = {
35
+ 'Content-Type' => 'application/json',
36
+ 'User-Agent' => @user_agent
37
+ }
38
+ end
39
+
40
+ def self.default
41
+ @@default ||= ApiClient.new
42
+ end
43
+
44
+ # Call an API with given options.
45
+ #
46
+ # @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
47
+ # the data deserialized from response body (could be nil), response status code and response headers.
48
+ def call_api(http_method, path, opts = {})
49
+ request = build_request(http_method, path, opts)
50
+ response = request.run
51
+
52
+ if @config.debugging
53
+ @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
54
+ end
55
+
56
+ unless response.success?
57
+ if response.timed_out?
58
+ fail ApiError.new('Connection timed out')
59
+ elsif response.code == 0
60
+ # Errors from libcurl will be made visible here
61
+ fail ApiError.new(:code => 0,
62
+ :message => response.return_message)
63
+ else
64
+ fail ApiError.new(:code => response.code,
65
+ :response_headers => response.headers,
66
+ :response_body => response.body),
67
+ response.status_message
68
+ end
69
+ end
70
+
71
+ if opts[:return_type]
72
+ data = deserialize(response, opts[:return_type])
73
+ else
74
+ data = nil
75
+ end
76
+ return data, response.code, response.headers
77
+ end
78
+
79
+ # Builds the HTTP request
80
+ #
81
+ # @param [String] http_method HTTP method/verb (e.g. POST)
82
+ # @param [String] path URL path (e.g. /account/new)
83
+ # @option opts [Hash] :header_params Header parameters
84
+ # @option opts [Hash] :query_params Query parameters
85
+ # @option opts [Hash] :form_params Query parameters
86
+ # @option opts [Object] :body HTTP body (JSON/XML)
87
+ # @return [Typhoeus::Request] A Typhoeus Request
88
+ def build_request(http_method, path, opts = {})
89
+ url = build_request_url(path)
90
+ http_method = http_method.to_sym.downcase
91
+
92
+ header_params = @default_headers.merge(opts[:header_params] || {})
93
+ query_params = opts[:query_params] || {}
94
+ form_params = opts[:form_params] || {}
95
+
96
+ update_params_for_auth! header_params, query_params, opts[:auth_names]
97
+
98
+ # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
99
+ _verify_ssl_host = @config.verify_ssl_host ? 2 : 0
100
+
101
+ req_opts = {
102
+ :method => http_method,
103
+ :headers => header_params,
104
+ :params => query_params,
105
+ :params_encoding => @config.params_encoding,
106
+ :timeout => @config.timeout,
107
+ :ssl_verifypeer => @config.verify_ssl,
108
+ :ssl_verifyhost => _verify_ssl_host,
109
+ :sslcert => @config.cert_file,
110
+ :sslkey => @config.key_file,
111
+ :verbose => @config.debugging
112
+ }
113
+
114
+ # set custom cert, if provided
115
+ req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
116
+
117
+ if [:post, :patch, :put, :delete].include?(http_method)
118
+ req_body = build_request_body(header_params, form_params, opts[:body])
119
+ req_opts.update :body => req_body
120
+ if @config.debugging
121
+ @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
122
+ end
123
+ end
124
+
125
+ request = Typhoeus::Request.new(url, req_opts)
126
+ download_file(request) if opts[:return_type] == 'File'
127
+ request
128
+ end
129
+
130
+ # Builds the HTTP request body
131
+ #
132
+ # @param [Hash] header_params Header parameters
133
+ # @param [Hash] form_params Query parameters
134
+ # @param [Object] body HTTP body (JSON/XML)
135
+ # @return [String] HTTP body data in the form of string
136
+ def build_request_body(header_params, form_params, body)
137
+ # http form
138
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
139
+ header_params['Content-Type'] == 'multipart/form-data'
140
+ data = {}
141
+ form_params.each do |key, value|
142
+ case value
143
+ when ::File, ::Array, nil
144
+ # let typhoeus handle File, Array and nil parameters
145
+ data[key] = value
146
+ else
147
+ data[key] = value.to_s
148
+ end
149
+ end
150
+ elsif body
151
+ data = body.is_a?(String) ? body : body.to_json
152
+ else
153
+ data = nil
154
+ end
155
+ data
156
+ end
157
+
158
+ # Check if the given MIME is a JSON MIME.
159
+ # JSON MIME examples:
160
+ # application/json
161
+ # application/json; charset=UTF8
162
+ # APPLICATION/JSON
163
+ # */*
164
+ # @param [String] mime MIME
165
+ # @return [Boolean] True if the MIME is application/json
166
+ def json_mime?(mime)
167
+ (mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
168
+ end
169
+
170
+ # Deserialize the response to the given return type.
171
+ #
172
+ # @param [Response] response HTTP response
173
+ # @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
174
+ def deserialize(response, return_type)
175
+ body = response.body
176
+
177
+ # handle file downloading - return the File instance processed in request callbacks
178
+ # note that response body is empty when the file is written in chunks in request on_body callback
179
+ return @tempfile if return_type == 'File'
180
+
181
+ return nil if body.nil? || body.empty?
182
+
183
+ # return response body directly for String return type
184
+ return body if return_type == 'String'
185
+
186
+ # ensuring a default content type
187
+ content_type = response.headers['Content-Type'] || 'application/json'
188
+
189
+ fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
190
+
191
+ begin
192
+ data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
193
+ rescue JSON::ParserError => e
194
+ if %w(String Date DateTime).include?(return_type)
195
+ data = body
196
+ else
197
+ raise e
198
+ end
199
+ end
200
+
201
+ convert_to_type data, return_type
202
+ end
203
+
204
+ # Convert data to the given return type.
205
+ # @param [Object] data Data to be converted
206
+ # @param [String] return_type Return type
207
+ # @return [Mixed] Data in a particular type
208
+ def convert_to_type(data, return_type)
209
+ return nil if data.nil?
210
+ case return_type
211
+ when 'String'
212
+ data.to_s
213
+ when 'Integer'
214
+ data.to_i
215
+ when 'Float'
216
+ data.to_f
217
+ when 'Boolean'
218
+ data == true
219
+ when 'DateTime'
220
+ # parse date time (expecting ISO 8601 format)
221
+ DateTime.parse data
222
+ when 'Date'
223
+ # parse date time (expecting ISO 8601 format)
224
+ Date.parse data
225
+ when 'Object'
226
+ # generic object (usually a Hash), return directly
227
+ data
228
+ when /\AArray<(.+)>\z/
229
+ # e.g. Array<Pet>
230
+ sub_type = $1
231
+ data.map { |item| convert_to_type(item, sub_type) }
232
+ when /\AHash\<String, (.+)\>\z/
233
+ # e.g. Hash<String, Integer>
234
+ sub_type = $1
235
+ {}.tap do |hash|
236
+ data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
237
+ end
238
+ else
239
+ # models, e.g. Pet
240
+ SwaggerClient.const_get(return_type).build_from_hash(data)
241
+ end
242
+ end
243
+
244
+ # Save response body into a file in (the defined) temporary folder, using the filename
245
+ # from the "Content-Disposition" header if provided, otherwise a random filename.
246
+ # The response body is written to the file in chunks in order to handle files which
247
+ # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
248
+ # process can use.
249
+ #
250
+ # @see Configuration#temp_folder_path
251
+ def download_file(request)
252
+ tempfile = nil
253
+ encoding = nil
254
+ request.on_headers do |response|
255
+ content_disposition = response.headers['Content-Disposition']
256
+ if content_disposition && content_disposition =~ /filename=/i
257
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
258
+ prefix = sanitize_filename(filename)
259
+ else
260
+ prefix = 'download-'
261
+ end
262
+ prefix = prefix + '-' unless prefix.end_with?('-')
263
+ encoding = response.body.encoding
264
+ tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
265
+ @tempfile = tempfile
266
+ end
267
+ request.on_body do |chunk|
268
+ chunk.force_encoding(encoding)
269
+ tempfile.write(chunk)
270
+ end
271
+ request.on_complete do |response|
272
+ if tempfile
273
+ tempfile.close
274
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
275
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
276
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
277
+ "explicitly with `tempfile.delete`"
278
+ end
279
+ end
280
+ end
281
+
282
+ # Sanitize filename by removing path.
283
+ # e.g. ../../sun.gif becomes sun.gif
284
+ #
285
+ # @param [String] filename the filename to be sanitized
286
+ # @return [String] the sanitized filename
287
+ def sanitize_filename(filename)
288
+ filename.gsub(/.*[\/\\]/, '')
289
+ end
290
+
291
+ def build_request_url(path)
292
+ # Add leading and trailing slashes to path
293
+ path = "/#{path}".gsub(/\/+/, '/')
294
+ @config.base_url + path
295
+ end
296
+
297
+ # Update hearder and query params based on authentication settings.
298
+ #
299
+ # @param [Hash] header_params Header parameters
300
+ # @param [Hash] query_params Query parameters
301
+ # @param [String] auth_names Authentication scheme name
302
+ def update_params_for_auth!(header_params, query_params, auth_names)
303
+ Array(auth_names).each do |auth_name|
304
+ auth_setting = @config.auth_settings[auth_name]
305
+ next unless auth_setting
306
+ case auth_setting[:in]
307
+ when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
308
+ when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
309
+ else fail ArgumentError, 'Authentication token must be in `query` of `header`'
310
+ end
311
+ end
312
+ end
313
+
314
+ # Sets user agent in HTTP header
315
+ #
316
+ # @param [String] user_agent User agent (e.g. swagger-codegen/ruby/1.0.0)
317
+ def user_agent=(user_agent)
318
+ @user_agent = user_agent
319
+ @default_headers['User-Agent'] = @user_agent
320
+ end
321
+
322
+ # Return Accept header based on an array of accepts provided.
323
+ # @param [Array] accepts array for Accept
324
+ # @return [String] the Accept header (e.g. application/json)
325
+ def select_header_accept(accepts)
326
+ return nil if accepts.nil? || accepts.empty?
327
+ # use JSON when present, otherwise use all of the provided
328
+ json_accept = accepts.find { |s| json_mime?(s) }
329
+ json_accept || accepts.join(',')
330
+ end
331
+
332
+ # Return Content-Type header based on an array of content types provided.
333
+ # @param [Array] content_types array for Content-Type
334
+ # @return [String] the Content-Type header (e.g. application/json)
335
+ def select_header_content_type(content_types)
336
+ # use application/json by default
337
+ return 'application/json' if content_types.nil? || content_types.empty?
338
+ # use JSON when present, otherwise use the first one
339
+ json_content_type = content_types.find { |s| json_mime?(s) }
340
+ json_content_type || content_types.first
341
+ end
342
+
343
+ # Convert object (array, hash, object, etc) to JSON string.
344
+ # @param [Object] model object to be converted into JSON string
345
+ # @return [String] JSON string representation of the object
346
+ def object_to_http_body(model)
347
+ return model if model.nil? || model.is_a?(String)
348
+ local_body = nil
349
+ if model.is_a?(Array)
350
+ local_body = model.map { |m| object_to_hash(m) }
351
+ else
352
+ local_body = object_to_hash(model)
353
+ end
354
+ local_body.to_json
355
+ end
356
+
357
+ # Convert object(non-array) to hash.
358
+ # @param [Object] obj object to be converted into JSON string
359
+ # @return [String] JSON string representation of the object
360
+ def object_to_hash(obj)
361
+ if obj.respond_to?(:to_hash)
362
+ obj.to_hash
363
+ else
364
+ obj
365
+ end
366
+ end
367
+
368
+ # Build parameter value according to the given collection format.
369
+ # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
370
+ def build_collection_param(param, collection_format)
371
+ case collection_format
372
+ when :csv
373
+ param.join(',')
374
+ when :ssv
375
+ param.join(' ')
376
+ when :tsv
377
+ param.join("\t")
378
+ when :pipes
379
+ param.join('|')
380
+ when :multi
381
+ # return the array directly as typhoeus will handle it as expected
382
+ param
383
+ else
384
+ fail "unknown collection format: #{collection_format.inspect}"
385
+ end
386
+ end
387
+ end
388
+ end