Module: Auth0::Api::V2::Clients

Included in:
Auth0::Api::V2
Defined in:
lib/auth0/api/v2/clients.rb

Overview

Methods to use the client endpoints

Instance Method Summary collapse

Instance Method Details

#client(client_id, fields: nil, include_fields: nil) ⇒ json

Retrieves a client by its id.

Parameters:

  • client_id (string)

    The id of the client to retrieve.

  • fields (string)

    A comma separated list of fields to include or exclude from the result.

  • include_fields (boolean)

    True if the fields specified are to be included in the result, false otherwise.

Returns:

  • (json)

    Returns the requested client application.

Raises:

See Also:


45
46
47
48
49
50
51
52
53
54
# File 'lib/auth0/api/v2/clients.rb', line 45

def client(client_id, fields: nil, include_fields: nil)
  raise Auth0::MissingClientId, 'Must specify a client id' if client_id.to_s.empty?
  include_fields = true if !fields.nil? && include_fields.nil?
  request_params = {
    fields: fields,
    include_fields: include_fields
  }
  path = "#{clients_path}/#{client_id}"
  get(path, request_params)
end

#clients(fields: nil, include_fields: nil, page: nil, per_page: nil) ⇒ json Also known as: get_clients

Retrieves a list of all client applications. Accepts a list of fields to include or exclude.

Parameters:

  • fields (string|Array)

    A comma separated list or an array of fields.

  • include_fields (boolean)

    True if the fields specified are to be included in the result, false otherwise.

  • page (int)

    Page number to get, 0-based.

  • per_page (int)

    Results per page if also passing a page number.

Returns:

  • (json)

    Returns the clients applications.

See Also:


15
16
17
18
19
20
21
22
23
24
# File 'lib/auth0/api/v2/clients.rb', line 15

def clients(fields: nil, include_fields: nil, page: nil, per_page: nil)
  include_fields = true if !fields.nil? && include_fields.nil?
  request_params = {
    fields: fields.is_a?(Array) ? fields.join(',') : fields,
    include_fields: include_fields,
    page: !page.nil? ? page.to_i : nil,
    per_page: !page.nil? && !per_page.nil? ? per_page.to_i : nil
  }
  get(clients_path, request_params)
end

#create_client(name, options = {}) ⇒ json

Creates a new client application.

Parameters:

  • name (string)

    The name of the client. Must contain at least one character. Does not allow '<' or '>'.

  • options (hash) (defaults to: {})

    The Hash options used to define the client's properties.

Returns:

  • (json)

    Returns the created client application.

Raises:

See Also:


32
33
34
35
36
37
# File 'lib/auth0/api/v2/clients.rb', line 32

def create_client(name, options = {})
  raise Auth0::MissingParameter, 'Must specify a valid client name' if name.to_s.empty?
  request_params = Hash[options.map { |(k, v)| [k.to_sym, v] }]
  request_params[:name] = name
  post(clients_path, request_params)
end

#delete_client(client_id) ⇒ Object

Deletes a client and all its related assets (like rules, connections, etc) given its id.

Parameters:

  • client_id (string)

    The id of the client to delete.

Raises:

See Also:


59
60
61
62
63
# File 'lib/auth0/api/v2/clients.rb', line 59

def delete_client(client_id)
  raise Auth0::MissingClientId, 'Must specify a client id' if client_id.to_s.empty?
  path = "#{clients_path}/#{client_id}"
  delete(path)
end

#patch_client(client_id, options) ⇒ Object

Updates a client.

Parameters:

  • client_id (string)

    The id of the client to update.

  • options (hash)

    The Hash options used to define the client's properties.

Raises:

See Also:


69
70
71
72
73
74
# File 'lib/auth0/api/v2/clients.rb', line 69

def patch_client(client_id, options)
  raise Auth0::MissingClientId, 'Must specify a client id' if client_id.to_s.empty?
  raise Auth0::MissingParameter, 'Must specify a valid body' if options.to_s.empty?
  path = "#{clients_path}/#{client_id}"
  patch(path, options)
end