Class: Usps::JwtAuth::Encode
- Inherits:
-
Object
- Object
- Usps::JwtAuth::Encode
- Defined in:
- lib/usps/jwt_auth/encode.rb
Overview
Encode data as a JWT
Class Method Summary collapse
Instance Method Summary collapse
- #encode(data) ⇒ Object
- #fingerprint ⇒ Object
-
#initialize(expiration_time: 15 * 60, audience: [], issuer: nil) ⇒ Encode
constructor
A new instance of Encode.
- #public_key ⇒ Object
Constructor Details
#initialize(expiration_time: 15 * 60, audience: [], issuer: nil) ⇒ Encode
Returns a new instance of Encode.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/usps/jwt_auth/encode.rb', line 12 def initialize(expiration_time: 15 * 60, audience: [], issuer: nil) private_key @expiration_time = expiration_time @audience = audience @issuer = issuer rescue StandardError @private_key = generate_private_key store_private_key retry ensure store_public_key end |
Class Method Details
.encode(data, expiration_time: 15 * 60, audience: [], issuer: nil) ⇒ Object
8 9 10 |
# File 'lib/usps/jwt_auth/encode.rb', line 8 def self.encode(data, expiration_time: 15 * 60, audience: [], issuer: nil) new(expiration_time: expiration_time, audience: audience, issuer: issuer).encode(data) end |
Instance Method Details
#encode(data) ⇒ Object
25 26 27 |
# File 'lib/usps/jwt_auth/encode.rb', line 25 def encode(data) JWT.encode(payload(data), private_key, JwtAuth.config.algorithm) end |
#fingerprint ⇒ Object
33 34 35 |
# File 'lib/usps/jwt_auth/encode.rb', line 33 def fingerprint OpenSSL::Digest::SHA256.new(public_key.to_der).to_s end |
#public_key ⇒ Object
29 30 31 |
# File 'lib/usps/jwt_auth/encode.rb', line 29 def public_key @public_key ||= private_key.public_key end |