Skip to content

Instantly share code, notes, and snippets.

@rwehresmann
Created May 12, 2019 02:30
Show Gist options
  • Select an option

  • Save rwehresmann/86b2cbb99eb9933488a018500e0ddbe2 to your computer and use it in GitHub Desktop.

Select an option

Save rwehresmann/86b2cbb99eb9933488a018500e0ddbe2 to your computer and use it in GitHub Desktop.
Knock.setup do |config|
if Rails.env.test?
config.token_secret_signature_key = -> { Rails.application.credentials.read }
else
config.token_audience = -> { ENV['AUTH0_AUDIENCE'] }
# Auth0 uses RS256.
config.token_signature_algorithm = 'RS256'
# API secret from Auth0.
config.token_secret_signature_key = -> { ENV['AUTH0_CLIENT_SECRET'] }
# RS256 is an asymmetric algorithm, which means it requires a private and public key.
jwks_raw = HTTP.get(ENV['AUTH0_RSA_DOMAIN']).body.to_s
jwks_keys = Array(JSON.parse(jwks_raw)['keys'])
config.token_public_key = OpenSSL::X509::Certificate.new(Base64.decode64(jwks_keys[0]['x5c'].first)).public_key
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment