Class: Nonnative::PasetoToken
- Inherits:
-
Object
- Object
- Nonnative::PasetoToken
- Defined in:
- lib/nonnative/paseto_token.rb
Overview
Generates Ed25519 PASETO v4.public tokens for authenticating against services under test.
The key id is carried in a JSON footer ({"kid":"..."}), and the claims match the common
iss/aud/sub/iat/nbf/exp/jti set expected by verifiers such as go-service. The signing library is
required lazily so that requiring nonnative does not depend on rbnacl/libsodium being present.
Instance Method Summary collapse
-
#generate(aud:, sub:) ⇒ String
Generates a signed PASETO v4.public token.
-
#initialize(issuer:, key:, private_key:, expiration:) ⇒ PasetoToken
constructor
A new instance of PasetoToken.
Constructor Details
#initialize(issuer:, key:, private_key:, expiration:) ⇒ PasetoToken
Returns a new instance of PasetoToken.
20 21 22 23 24 25 |
# File 'lib/nonnative/paseto_token.rb', line 20 def initialize(issuer:, key:, private_key:, expiration:) @issuer = issuer @key = key @ed25519 = Nonnative::Ed25519Key.new(private_key) @expiration = expiration end |
Instance Method Details
#generate(aud:, sub:) ⇒ String
Generates a signed PASETO v4.public token.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/nonnative/paseto_token.rb', line 32 def generate(aud:, sub:) load_dependencies! now = Time.now.utc claims = { 'iss' => @issuer, 'aud' => aud, 'sub' => sub, 'iat' => now.iso8601, 'nbf' => now.iso8601, 'exp' => (now + @expiration).iso8601, 'jti' => SecureRandom.uuid } Paseto::V4::Public.new(@ed25519.pem).encode!(claims, footer: { 'kid' => @key }.to_json) end |