Module: Auth0::Api::V2::ResourceServers

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

Overview

Methods to use the resource servers endpoints

Instance Method Summary collapse

Instance Method Details

#create_resource_server(identifier, options = {}) ⇒ json

Creates a new resource server according to the JSON object received in body.

Parameters:

  • identifier (string)

    The identifier of the resource server.

  • options (hash) (defaults to: {})
    • :name [string] The name of the resource server. Must contain at least one character. Does not allow ‘<’ or ‘>’.

    • :signing_alg [string] The algorithm used to sign tokens.

    • :signing_secret [string] The secret used to sign tokens when using symmetric algorithms.

    • :token_lifetime [integer] The amount of time (in seconds) that the token will be valid after being issued.

    • :scopes [array] The scope of the resource server.

Returns:

  • (json)

    Returns the resource server.

Raises:

See Also:



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

def create_resource_server(identifier, options = {})
  raise Auth0::InvalidParameter, 'Must supply a valid resource server id' if identifier.to_s.empty?
  if options.fetch(:name, '').index(/[<>]/)
    raise Auth0::InvalidParameter, 'Name must contain at least one character. Does not allow "<" or ">"'
  end
  request_params = Hash[options.map { |(k, v)| [k.to_sym, v] }]
  request_params[:identifier] = identifier
  post(resource_servers_path, request_params)
end

#delete_resource_server(resource_server_id) ⇒ Object

Deletes a resource server by its ID.

Parameters:

  • resource_server_id (string)

    The id of the resource server to delete.

Raises:

See Also:



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

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

#patch_resource_server(id, body) ⇒ Object

Updates a resource server.

Parameters:

  • id (string)

    The id or audience of the resource server to update.

  • body (hash)

    The Hash options used to define the resource servers’s properties.

Raises:

See Also:



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

def patch_resource_server(id, body)
  raise Auth0::InvalidParameter, 'Must specify a resource server id or audience' if id.to_s.empty?
  raise Auth0::InvalidParameter, 'Must specify a valid body' if body.to_s.empty?
  path = "#{resource_servers_path}/#{id}"
  patch(path, body)
end

#resource_server(resource_server_id) ⇒ json Also known as: get_resource_server

Retrieves a resource server by its ID.

Parameters:

  • resource_server_id (string)

    The id of the resource server to retrieve.

Returns:

  • (json)

    Returns the resource server.

Raises:

See Also:



27
28
29
30
31
# File 'lib/auth0/api/v2/resource_servers.rb', line 27

def resource_server(resource_server_id)
  raise Auth0::InvalidParameter, 'Must supply a valid resource server id' if resource_server_id.to_s.empty?
  path = "#{resource_servers_path}/#{resource_server_id}"
  get(path)
end

#resource_servers(page: nil, per_page: nil) ⇒ json Also known as: get_resource_servers

Retrieves a list of all resource servers.

Parameters:

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

See Also:



13
14
15
16
17
18
19
# File 'lib/auth0/api/v2/resource_servers.rb', line 13

def resource_servers(page: nil, per_page: nil)
  request_params = {
    page: !page.nil? ? page.to_i : nil,
    per_page: !page.nil? && !per_page.nil? ? per_page.to_i : nil
  }
  get(resource_servers_path, request_params)
end