Sha256: d21e8338178c31c3fe94a98ce6b3a3e90b051d3ecf0e8bfb5815c3707c52f397
Contents?: true
Size: 1.11 KB
Versions: 1
Compression:
Stored size: 1.11 KB
Contents
require 'soar_xt' require 'jwt' require 'securerandom' module SoarAuthenticationToken class TokenGenerator DEFAULT_CONFIGURATION = { 'mode' => 'remote', 'url' => '' } unless defined? DEFAULT_CONFIGURATION; DEFAULT_CONFIGURATION.freeze def initialize(configuration) @configuration = merge_with_default_configuration(configuration) validate_configuration @private_key = OpenSSL::PKey::EC.new(@configuration['private_key']) end def generate(authenticated_identifier:) encode(payload(authenticated_identifier)) end private def payload(authenticated_identifier) { 'authenticated_identifier' => authenticated_identifier, 'issue_time' => Time.now.utc.iso8601(3), 'nounce' => SecureRandom.hex(32) } end def encode(payload) JWT.encode(payload, @private_key, 'ES512') end def validate_configuration end def merge_with_default_configuration(configuration) configuration = {} unless configuration Hash.deep_merge(DEFAULT_CONFIGURATION,configuration) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
soar_authentication_token-0.0.2 | lib/soar_authentication_token/token_generator.rb |