Class: Auth0::Clients::Credentials::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/auth0/clients/credentials/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void

Parameters:



10
11
12
# File 'lib/auth0/clients/credentials/client.rb', line 10

def initialize(client:)
  @client = client
end

Instance Method Details

#create(request_options: {}, **params) ⇒ Auth0::Types::PostClientCredentialResponseContent

Create a client credential associated to your application. Credentials can be used to configure Private Key JWT and mTLS authentication methods, as well as for JWT-secured Authorization requests.

**Public Key**

Public Key credentials can be used to set up Private Key JWT client authentication and JWT-secured Authorization requests.

Sample:

“‘json

"credential_type": "public_key",
"name": "string",
"pem": "string",
"alg": "RS256",
"parse_expiry_from_cert": false,
"expires_at": "2022-12-31T23:59:59Z"

“‘

**Certificate (CA-signed & self-signed)**

Certificate credentials can be used to set up mTLS client authentication. CA-signed certificates can be configured either with a signed certificate or with just the certificate Subject DN.

CA-signed Certificate Sample (pem):

“‘json

"credential_type": "x509_cert",
"name": "string",
"pem": "string"

“‘

CA-signed Certificate Sample (subject_dn):

“‘json

"credential_type": "cert_subject_dn",
"name": "string",
"subject_dn": "string"

“‘

Self-signed Certificate Sample:

“‘json

"credential_type": "cert_subject_dn",
"name": "string",
"pem": "string"

“‘

The credential will be created but not yet enabled for use until you set the corresponding properties in the client:

  • To enable the credential for Private Key JWT or mTLS authentication methods, set the

‘client_authentication_methods` property on the client. For more information, read [Configure Private Key JWT Authentication](auth0.com/docs/get-started/applications/configure-private-key-jwt) and [Configure mTLS Authentication](auth0.com/docs/get-started/applications/configure-mtls)

  • To enable the credential for JWT-secured Authorization requests, set the ‘signed_request_object`property on

the client. For more information, read [Configure JWT-secured Authorization Requests (JAR)](auth0.com/docs/get-started/applications/configure-jar)

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :client_id (String)

Returns:



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/auth0/clients/credentials/client.rb', line 127

def create(request_options: {}, **params)
  params = Auth0::Internal::Types::Utils.normalize_keys(params)
  request_data = Auth0::Clients::Credentials::Types::PostClientCredentialRequestContent.new(params).to_h
  non_body_param_names = %w[client_id]
  body = request_data.except(*non_body_param_names)

  request = Auth0::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "clients/#{URI.encode_uri_component(params[:client_id].to_s)}/credentials",
    body: body,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Auth0::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Auth0::Types::PostClientCredentialResponseContent.load(response.body)
  else
    error_class = Auth0::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#delete(request_options: {}, **params) ⇒ untyped

Delete a client credential you previously created. May be enabled or disabled. For more information, read <a href=“www.auth0.com/docs/get-started/authentication-and-authorization-flow/client-credentials-flow”>Client Credential Flow</a>.

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :client_id (String)
  • :credential_id (String)

Returns:

  • (untyped)

Raises:

  • (error_class)


208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/auth0/clients/credentials/client.rb', line 208

def delete(request_options: {}, **params)
  params = Auth0::Internal::Types::Utils.normalize_keys(params)
  request = Auth0::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "DELETE",
    path: "clients/#{URI.encode_uri_component(params[:client_id].to_s)}/credentials/#{URI.encode_uri_component(params[:credential_id].to_s)}",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Auth0::Errors::TimeoutError
  end
  code = response.code.to_i
  return if code.between?(200, 299)

  error_class = Auth0::Errors::ResponseError.subclass_for_code(code)
  raise error_class.new(response.body, code: code)
end

#get(request_options: {}, **params) ⇒ Auth0::Types::GetClientCredentialResponseContent

Get the details of a client credential.

Important: To enable credentials to be used for a client authentication method, set the ‘client_authentication_methods` property on the client. To enable credentials to be used for JWT-Secured Authorization requests set the `signed_request_object` property on the client.

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :client_id (String)
  • :credential_id (String)

Returns:



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/auth0/clients/credentials/client.rb', line 171

def get(request_options: {}, **params)
  params = Auth0::Internal::Types::Utils.normalize_keys(params)
  request = Auth0::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "clients/#{URI.encode_uri_component(params[:client_id].to_s)}/credentials/#{URI.encode_uri_component(params[:credential_id].to_s)}",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Auth0::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Auth0::Types::GetClientCredentialResponseContent.load(response.body)
  else
    error_class = Auth0::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#list(request_options: {}, **params) ⇒ Array[Auth0::Types::ClientCredential]

Get the details of a client credential.

Important: To enable credentials to be used for a client authentication method, set the ‘client_authentication_methods` property on the client. To enable credentials to be used for JWT-Secured Authorization requests set the `signed_request_object` property on the client.

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :client_id (String)

Returns:

Raises:

  • (error_class)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/auth0/clients/credentials/client.rb', line 30

def list(request_options: {}, **params)
  params = Auth0::Internal::Types::Utils.normalize_keys(params)
  request = Auth0::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "clients/#{URI.encode_uri_component(params[:client_id].to_s)}/credentials",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Auth0::Errors::TimeoutError
  end
  code = response.code.to_i
  return if code.between?(200, 299)

  error_class = Auth0::Errors::ResponseError.subclass_for_code(code)
  raise error_class.new(response.body, code: code)
end

#update(request_options: {}, **params) ⇒ Auth0::Types::PatchClientCredentialResponseContent

Change a client credential you previously created. May be enabled or disabled. For more information, read <a href=“www.auth0.com/docs/get-started/authentication-and-authorization-flow/client-credentials-flow”>Client Credential Flow</a>.

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :client_id (String)
  • :credential_id (String)

Returns:



243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/auth0/clients/credentials/client.rb', line 243

def update(request_options: {}, **params)
  params = Auth0::Internal::Types::Utils.normalize_keys(params)
  request_data = Auth0::Clients::Credentials::Types::PatchClientCredentialRequestContent.new(params).to_h
  non_body_param_names = %w[client_id credential_id]
  body = request_data.except(*non_body_param_names)

  request = Auth0::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "PATCH",
    path: "clients/#{URI.encode_uri_component(params[:client_id].to_s)}/credentials/#{URI.encode_uri_component(params[:credential_id].to_s)}",
    body: body,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Auth0::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Auth0::Types::PatchClientCredentialResponseContent.load(response.body)
  else
    error_class = Auth0::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end