Class: ClerkHttpClient::SessionsApi

Inherits:
Object
  • Object
show all
Defined in:
lib/clerk-http-client/api/sessions_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_client = ApiClient.default) ⇒ SessionsApi

Returns a new instance of SessionsApi.



19
20
21
# File 'lib/clerk-http-client/api/sessions_api.rb', line 19

def initialize(api_client = ApiClient.default)
  @api_client = api_client
end

Instance Attribute Details

#api_clientObject

Returns the value of attribute api_client.



17
18
19
# File 'lib/clerk-http-client/api/sessions_api.rb', line 17

def api_client
  @api_client
end

Instance Method Details

#all(opts = {}) ⇒ Array<Session>

List all sessions Returns a list of all sessions. The sessions are returned sorted by creation date, with the newest sessions appearing first. **Deprecation Notice (2024-01-01):** All parameters were initially considered optional, however moving forward at least one of ‘client_id` or `user_id` parameters should be provided.

Parameters:

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

  • :client_id (String)

    List sessions for the given client

  • :user_id (String)

    List sessions for the given user

  • :status (String)

    Filter sessions by the provided status

  • :limit (Float)

    Applies a limit to the number of results returned. Can be used for paginating the results together with &#x60;offset&#x60;. (default to 10)

  • :offset (Float)

    Skip the first &#x60;offset&#x60; results when paginating. Needs to be an integer greater or equal to zero. To be used in conjunction with &#x60;limit&#x60;. (default to 0)

Returns:



168
169
170
171
# File 'lib/clerk-http-client/api/sessions_api.rb', line 168

def all(opts = {})
  data, _status_code, _headers = all_with_http_info(opts)
  data
end

#all_with_http_info(opts = {}) ⇒ Array<(Array<Session>, Integer, Hash)>

List all sessions Returns a list of all sessions. The sessions are returned sorted by creation date, with the newest sessions appearing first. **Deprecation Notice (2024-01-01):** All parameters were initially considered optional, however moving forward at least one of &#x60;client_id&#x60; or &#x60;user_id&#x60; parameters should be provided. GET array

Parameters:

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

  • :client_id (String)

    List sessions for the given client

  • :user_id (String)

    List sessions for the given user

  • :status (String)

    Filter sessions by the provided status

  • :limit (Float)

    Applies a limit to the number of results returned. Can be used for paginating the results together with &#x60;offset&#x60;. (default to 10)

  • :offset (Float)

    Skip the first &#x60;offset&#x60; results when paginating. Needs to be an integer greater or equal to zero. To be used in conjunction with &#x60;limit&#x60;. (default to 0)

Returns:

  • (Array<(Array<Session>, Integer, Hash)>)

    Array<Session> data, response status code and response headers



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/clerk-http-client/api/sessions_api.rb', line 183

def all_with_http_info(opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: SessionsApi.get_session_list ...'
  end
  allowable_values = ["abandoned", "active", "ended", "expired", "removed", "replaced", "revoked"]
  if @api_client.config.client_side_validation && opts[:'status'] && !allowable_values.include?(opts[:'status'])
    fail ArgumentError, "invalid value for \"status\", must be one of #{allowable_values}"
  end
  if @api_client.config.client_side_validation && !opts[:'limit'].nil? && opts[:'limit'] > 500
    fail ArgumentError, 'invalid value for "opts[:"limit"]" when calling SessionsApi.get_session_list, must be smaller than or equal to 500.'
  end

  if @api_client.config.client_side_validation && !opts[:'limit'].nil? && opts[:'limit'] < 1
    fail ArgumentError, 'invalid value for "opts[:"limit"]" when calling SessionsApi.get_session_list, must be greater than or equal to 1.'
  end

  if @api_client.config.client_side_validation && !opts[:'offset'].nil? && opts[:'offset'] < 0
    fail ArgumentError, 'invalid value for "opts[:"offset"]" when calling SessionsApi.get_session_list, must be greater than or equal to 0.'
  end

  # resource path
  local_var_path = '/sessions'

  # query parameters
  query_params = opts[:query_params] || {}
  query_params[:'client_id'] = opts[:'client_id'] if !opts[:'client_id'].nil?
  query_params[:'user_id'] = opts[:'user_id'] if !opts[:'user_id'].nil?
  query_params[:'status'] = opts[:'status'] if !opts[:'status'].nil?
  query_params[:'limit'] = opts[:'limit'] if !opts[:'limit'].nil?
  query_params[:'offset'] = opts[:'offset'] if !opts[:'offset'].nil?

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'Array<Session>'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['bearerAuth']

  new_options = opts.merge(
    :operation => :"SessionsApi.get_session_list",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: SessionsApi#get_session_list\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#create_token_from_template(session_id, template_name, opts = {}) ⇒ CreateSessionTokenFromTemplate200Response

Create a session token from a jwt template Creates a JSON Web Token(JWT) based on a session and a JWT Template name defined for your instance

Parameters:

  • session_id (String)

    The ID of the session

  • template_name (String)

    The name of the JWT Template defined in your instance (e.g. &#x60;custom_hasura&#x60;).

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



29
30
31
32
# File 'lib/clerk-http-client/api/sessions_api.rb', line 29

def create_token_from_template(session_id, template_name, opts = {})
  data, _status_code, _headers = create_token_from_template_with_http_info(session_id, template_name, opts)
  data
end

#create_token_from_template_with_http_info(session_id, template_name, opts = {}) ⇒ Array<(CreateSessionTokenFromTemplate200Response, Integer, Hash)>

Create a session token from a jwt template Creates a JSON Web Token(JWT) based on a session and a JWT Template name defined for your instance POST

Parameters:

  • session_id (String)

    The ID of the session

  • template_name (String)

    The name of the JWT Template defined in your instance (e.g. &#x60;custom_hasura&#x60;).

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/clerk-http-client/api/sessions_api.rb', line 41

def create_token_from_template_with_http_info(session_id, template_name, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: SessionsApi.create_session_token_from_template ...'
  end
  # verify the required parameter 'session_id' is set
  if @api_client.config.client_side_validation && session_id.nil?
    fail ArgumentError, "Missing the required parameter 'session_id' when calling SessionsApi.create_session_token_from_template"
  end
  # verify the required parameter 'template_name' is set
  if @api_client.config.client_side_validation && template_name.nil?
    fail ArgumentError, "Missing the required parameter 'template_name' when calling SessionsApi.create_session_token_from_template"
  end
  # resource path
  local_var_path = '/sessions/{session_id}/tokens/{template_name}'.sub('{' + 'session_id' + '}', CGI.escape(session_id.to_s)).sub('{' + 'template_name' + '}', CGI.escape(template_name.to_s))

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'CreateSessionTokenFromTemplate200Response'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['bearerAuth']

  new_options = opts.merge(
    :operation => :"SessionsApi.create_session_token_from_template",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: SessionsApi#create_session_token_from_template\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#find(session_id, opts = {}) ⇒ Session

Retrieve a session Retrieve the details of a session

Parameters:

  • session_id (String)

    The ID of the session

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



99
100
101
102
# File 'lib/clerk-http-client/api/sessions_api.rb', line 99

def find(session_id, opts = {})
  data, _status_code, _headers = find_with_http_info(session_id, opts)
  data
end

#find_with_http_info(session_id, opts = {}) ⇒ Array<(Session, Integer, Hash)>

Retrieve a session Retrieve the details of a session GET

Parameters:

  • session_id (String)

    The ID of the session

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(Session, Integer, Hash)>)

    Session data, response status code and response headers



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/clerk-http-client/api/sessions_api.rb', line 110

def find_with_http_info(session_id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: SessionsApi.get_session ...'
  end
  # verify the required parameter 'session_id' is set
  if @api_client.config.client_side_validation && session_id.nil?
    fail ArgumentError, "Missing the required parameter 'session_id' when calling SessionsApi.get_session"
  end
  # resource path
  local_var_path = '/sessions/{session_id}'.sub('{' + 'session_id' + '}', CGI.escape(session_id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'Session'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['bearerAuth']

  new_options = opts.merge(
    :operation => :"SessionsApi.get_session",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: SessionsApi#get_session\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#revoke(session_id, opts = {}) ⇒ Session

Revoke a session Sets the status of a session as "revoked", which is an unauthenticated state. In multi-session mode, a revoked session will still be returned along with its client object, however the user will need to sign in again.

Parameters:

  • session_id (String)

    The ID of the session

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



254
255
256
257
# File 'lib/clerk-http-client/api/sessions_api.rb', line 254

def revoke(session_id, opts = {})
  data, _status_code, _headers = revoke_with_http_info(session_id, opts)
  data
end

#revoke_with_http_info(session_id, opts = {}) ⇒ Array<(Session, Integer, Hash)>

Revoke a session Sets the status of a session as &quot;revoked&quot;, which is an unauthenticated state. In multi-session mode, a revoked session will still be returned along with its client object, however the user will need to sign in again. POST

Parameters:

  • session_id (String)

    The ID of the session

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(Session, Integer, Hash)>)

    Session data, response status code and response headers



265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# File 'lib/clerk-http-client/api/sessions_api.rb', line 265

def revoke_with_http_info(session_id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: SessionsApi.revoke_session ...'
  end
  # verify the required parameter 'session_id' is set
  if @api_client.config.client_side_validation && session_id.nil?
    fail ArgumentError, "Missing the required parameter 'session_id' when calling SessionsApi.revoke_session"
  end
  # resource path
  local_var_path = '/sessions/{session_id}/revoke'.sub('{' + 'session_id' + '}', CGI.escape(session_id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body]

  # return_type
  return_type = opts[:debug_return_type] || 'Session'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['bearerAuth']

  new_options = opts.merge(
    :operation => :"SessionsApi.revoke_session",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: SessionsApi#revoke_session\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end

#verify(session_id, opts = {}) ⇒ Session

Verify a session Returns the session if it is authenticated, otherwise returns an error. WARNING: This endpoint is deprecated and will be removed in future versions. We strongly recommend switching to networkless verification using short-lived session tokens, which is implemented transparently in all recent SDK versions (e.g. [NodeJS SDK](clerk.com/docs/backend-requests/handling/nodejs#clerk-express-require-auth)). For more details on how networkless verification works, refer to our [Session Tokens documentation](clerk.com/docs/backend-requests/resources/session-tokens).

Parameters:

  • session_id (String)

    The ID of the session

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

Returns:



320
321
322
323
# File 'lib/clerk-http-client/api/sessions_api.rb', line 320

def verify(session_id, opts = {})
  data, _status_code, _headers = verify_with_http_info(session_id, opts)
  data
end

#verify_with_http_info(session_id, opts = {}) ⇒ Array<(Session, Integer, Hash)>

Verify a session Returns the session if it is authenticated, otherwise returns an error. WARNING: This endpoint is deprecated and will be removed in future versions. We strongly recommend switching to networkless verification using short-lived session tokens, which is implemented transparently in all recent SDK versions (e.g. [NodeJS SDK](clerk.com/docs/backend-requests/handling/nodejs#clerk-express-require-auth)). For more details on how networkless verification works, refer to our [Session Tokens documentation](clerk.com/docs/backend-requests/resources/session-tokens). POST

Parameters:

  • session_id (String)

    The ID of the session

  • opts (Hash) (defaults to: {})

    the optional parameters

Options Hash (opts):

Returns:

  • (Array<(Session, Integer, Hash)>)

    Session data, response status code and response headers



332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# File 'lib/clerk-http-client/api/sessions_api.rb', line 332

def verify_with_http_info(session_id, opts = {})
  if @api_client.config.debugging
    @api_client.config.logger.debug 'Calling API: SessionsApi.verify_session ...'
  end
  # verify the required parameter 'session_id' is set
  if @api_client.config.client_side_validation && session_id.nil?
    fail ArgumentError, "Missing the required parameter 'session_id' when calling SessionsApi.verify_session"
  end
  # resource path
  local_var_path = '/sessions/{session_id}/verify'.sub('{' + 'session_id' + '}', CGI.escape(session_id.to_s))

  # query parameters
  query_params = opts[:query_params] || {}

  # header parameters
  header_params = opts[:header_params] || {}
  # HTTP header 'Accept' (if needed)
  header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
  # HTTP header 'Content-Type'
  content_type = @api_client.select_header_content_type(['application/json'])
  if !content_type.nil?
      header_params['Content-Type'] = content_type
  end

  # form parameters
  form_params = opts[:form_params] || {}

  # http body (model)
  post_body = opts[:debug_body] || @api_client.object_to_http_body(opts[:'verify_session_request'])

  # return_type
  return_type = opts[:debug_return_type] || 'Session'

  # auth_names
  auth_names = opts[:debug_auth_names] || ['bearerAuth']

  new_options = opts.merge(
    :operation => :"SessionsApi.verify_session",
    :header_params => header_params,
    :query_params => query_params,
    :form_params => form_params,
    :body => post_body,
    :auth_names => auth_names,
    :return_type => return_type
  )

  data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
  if @api_client.config.debugging
    @api_client.config.logger.debug "API called: SessionsApi#verify_session\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
  end
  return data, status_code, headers
end