Module: Auth0::ClientAssertion

Included in:
Api::AuthenticationEndpoints
Defined in:
lib/auth0/client_assertion.rb

Constant Summary collapse

CLIENT_ASSERTION_TYPE =
'urn:ietf:params:oauth:client-assertion-type:jwt-bearer'.freeze

Instance Method Summary collapse

Instance Method Details

#populate_client_assertion_or_secret(hash, domain: @domain, client_id: @client_id, client_secret: @client_secret, client_assertion_signing_key: @client_assertion_signing_key, client_assertion_signing_alg: @client_assertion_signing_alg) ⇒ Object

Adds keys into the supplied hash for either the client secret, or client assertion. If ‘client_assertion_signing_key` is not nil, it takes precedence over `client_secret`.

Parameters:

  • The (hash)

    hash to add the keys to

  • client_id (string) (defaults to: @client_id)

    The client ID

  • client_secret (string) (defaults to: @client_secret)

    The client secret

  • client_assertion_signing_key (PKey) (defaults to: @client_assertion_signing_key)

    The key used to sign the client assertion JWT

  • client_assertion_signing_alg (string) (defaults to: @client_assertion_signing_alg)

    The algorithm used when signing the client assertion JWT



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/auth0/client_assertion.rb', line 16

def populate_client_assertion_or_secret(hash, 
  domain: @domain,
  client_id: @client_id, 
  client_secret: @client_secret,
  client_assertion_signing_key: @client_assertion_signing_key,
  client_assertion_signing_alg: @client_assertion_signing_alg)

  if !client_assertion_signing_key.nil?
    # Create JWT
    now = Time.now.to_i

    payload = {
      iss: client_id,
      sub: client_id,
      aud: "https://#{domain}/",
      iat: now,
      exp: now + 180,
      jti: SecureRandom.uuid
    }

    jwt = JWT.encode payload, client_assertion_signing_key, client_assertion_signing_alg

    hash[:client_assertion] = jwt
    hash[:client_assertion_type] = Auth0::ClientAssertion::CLIENT_ASSERTION_TYPE
  else
    hash[:client_secret] = client_secret
  end
end