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.

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

Sample: <pre><code>

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

</code></pre> <h5>Certificate (CA-signed & self-signed)</h5>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): <pre><code>

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

</code></pre>CA-signed Certificate Sample (subject_dn): <pre><code>

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

</code></pre>Self-signed Certificate Sample: <pre><code>

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

</code></pre>

The credential will be created but not yet enabled for use until you set the corresponding properties in the client: <ul> <li>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 <a href=“auth0.com/docs/get-started/applications/configure-private-key-jwt”>Configure Private Key JWT Authentication</a> and <a href=“auth0.com/docs/get-started/applications/configure-mtls”>Configure mTLS Authentication</a></li> <li>To enable the credential for JWT-secured Authorization requests, set the signed_request_objectproperty on the client. For more information, read <a href=“auth0.com/docs/get-started/applications/configure-jar”>Configure JWT-secured Authorization Requests (JAR)</a></li> </ul>

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:



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/auth0/clients/credentials/client.rb', line 106

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 = ["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)


187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/auth0/clients/credentials/client.rb', line 187

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:



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/auth0/clients/credentials/client.rb', line 150

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:



222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/auth0/clients/credentials/client.rb', line 222

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