Module: Auth0::Api::V2::DeviceCredentials

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

Overview

Methods to use the device crenditials endpoints

Instance Method Summary collapse

Instance Method Details

#create_device_credential(device_name, value, device_id, client_id) ⇒ json Also known as: create_device_public_key

Creates a new device public key.

Parameters:

  • device_name (string)

    The device’s name, a value that must be easily recognized by the device’s owner.

  • value (string)

    A base64 encoded string with the value of the credential.

  • device_id (string)

    A unique identifier for the device.

  • client_id (string)

    The client_id of the client for which the credential will be created.

Returns:

  • (json)

    Returns the created public key.

Raises:

See Also:



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/auth0/api/v2/device_credentials.rb', line 42

def create_device_credential(device_name, value, device_id, client_id)
  raise Auth0::InvalidParameter, 'Must supply a valid device_name' if device_name.to_s.empty?
  raise Auth0::InvalidParameter, 'Must supply a valid value' if value.to_s.empty?
  raise Auth0::InvalidParameter, 'Must supply a valid device_id' if device_id.to_s.empty?
  raise Auth0::InvalidParameter, 'Must supply a valid client_id' if client_id.to_s.empty?
  request_params = {
    device_name:  device_name,
    type:         'public_key',
    value:        value,
    device_id:    device_id,
    client_id:    client_id
  }
  post(device_credentials_path, request_params)
end

#delete_device_credential(id) ⇒ Object

Deletes a single device credential given its id.

Parameters:

  • id (string)

    The id of the credential to delete.

Raises:

See Also:



61
62
63
64
65
# File 'lib/auth0/api/v2/device_credentials.rb', line 61

def delete_device_credential(id)
  raise Auth0::InvalidParameter, 'Must supply a valid id' if id.to_s.empty?
  path = "#{device_credentials_path}/#{id}"
  delete(path)
end

#device_credentials(client_id, options = {}) ⇒ json Also known as: list_device_credentials

Retrieves log entries that match the specified search criteria. rubocop:disable Metrics/AbcSize

Parameters:

  • 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.

  • user_id (string)

    The user_id of the devices to retrieve.

  • client_id (string)

    The client_id of the devices to retrieve.

  • type (string)

    The type of credentials. Possible values: ‘public_key’ or ‘refresh_token’.

Returns:

  • (json)

    Returns the list of existing devices for the specified client_id.

Raises:

See Also:



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/auth0/api/v2/device_credentials.rb', line 18

def device_credentials(client_id, options = {})
  request_params = {
    fields: options.fetch(:fields, nil),
    include_fields: options.fetch(:include_fields, nil),
    user_id: options.fetch(:user_id, nil),
    client_id: client_id,
    type: options.fetch(:type, nil)
  }
  raise Auth0::InvalidParameter, 'Must supply a valid client_id' if client_id.to_s.empty?
  if !request_params[:type].nil? && !%w(public_key refresh_token).include?(request_params[:type])
    raise Auth0::InvalidParameter, 'Type must be one of \'public_key\', \'refresh_token\''
  end
  get(device_credentials_path, request_params)
end