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) (defaults to: nil)

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

  • include_fields (boolean) (defaults to: nil)

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

Returns:

  • (json)

    Returns the requested client application.

Raises:

See Also:



42
43
44
45
46
47
48
49
50
51
# File 'lib/auth0/api/v2/clients.rb', line 42

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) ⇒ 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) (defaults to: nil)

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

  • include_fields (boolean) (defaults to: nil)

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

Returns:

  • (json)

    Returns the clients applications.

See Also:



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

def clients(fields: nil, include_fields: nil)
  include_fields = true if !fields.nil? && include_fields.nil?
  request_params = {
    fields: fields,
    include_fields: include_fields
  }
  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:



29
30
31
32
33
34
# File 'lib/auth0/api/v2/clients.rb', line 29

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:



56
57
58
59
60
# File 'lib/auth0/api/v2/clients.rb', line 56

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:



66
67
68
69
70
71
# File 'lib/auth0/api/v2/clients.rb', line 66

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