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:



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

#client_credential(client_id, credential_id) ⇒ hash Also known as: get_client_credential

Gets a client credential by ID

Parameters:

  • client_id (string)

    The Id of the client

  • credential_id (string)

    The Id of the credential to retrieve

Returns:

  • (hash)

    The credential

Raises:



98
99
100
101
102
# File 'lib/auth0/api/v2/clients.rb', line 98

def client_credential(client_id, credential_id)
  raise Auth0::MissingClientId, 'Must specify a client id' if client_id.to_s.empty?
  raise Auth0::MissingParameter, 'Must specify a credential id' if credential_id.to_s.empty?
  get("#{client_credentials_path(client_id)}/#{credential_id}")
end

#client_credentials(client_id) ⇒ hash Also known as: get_client_credentials

Gets the credentials for a client

Parameters:

  • client_id (string)

    The Id of the client

Returns:

  • (hash)

    The client credentials

Raises:



88
89
90
91
# File 'lib/auth0/api/v2/clients.rb', line 88

def client_credentials(client_id)
  raise Auth0::MissingClientId, 'Must specify a client id' if client_id.to_s.empty?
  get(client_credentials_path(client_id))
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) (defaults to: nil)

    A comma separated list or an array of fields.

  • include_fields (boolean) (defaults to: nil)

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

  • page (int) (defaults to: nil)

    Page number to get, 0-based.

  • per_page (int) (defaults to: nil)

    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

#create_client_credentials(client_id, options) ⇒ Object

Creates credentials for a client

Parameters:

  • client_id (string)

    The Id of the client to update

  • options (hash)

    The payload to send to the endpoint

Raises:



79
80
81
82
83
# File 'lib/auth0/api/v2/clients.rb', line 79

def create_client_credentials(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?
  post(client_credentials_path(client_id), options)
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

#delete_client_credential(client_id, credential_id) ⇒ Object

Deletes a credential from the specified client

Parameters:

  • client_id (string)

    The Id of the client

  • credential_id (string)

    The Id of the credential to delete

Raises:



108
109
110
111
112
# File 'lib/auth0/api/v2/clients.rb', line 108

def delete_client_credential(client_id, credential_id)
  raise Auth0::MissingClientId, 'Must specify a client id' if client_id.to_s.empty?
  raise Auth0::MissingParameter, 'Must specify a credential id' if credential_id.to_s.empty?
  delete("#{client_credentials_path(client_id)}/#{credential_id}")
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