Sha256: 2c014660018b619d1ca2ec8e39d73c9bafb2059e32293e4e75eb3f113db99160

Contents?: true

Size: 588 Bytes

Versions: 5

Compression:

Stored size: 588 Bytes

Contents

# typed: strict
# frozen_string_literal: true

require "jwt"

module Httpsensible
  module JWT
    JWT_ALGORITHM = "RS256"

    class << self
      def encode_jwt(pem, iss, iat: Time.now.to_i - 60, exp: Time.now.to_i + (10 * 60))
        private_key = OpenSSL::PKey::RSA.new(pem)
        payload = {
          # issued at time, 60 seconds in the past to allow for clock drift
          iat: iat,
          # JWT expiration time
          exp: exp,
          # Identifier
          iss: iss,
        }

        ::JWT.encode(payload, private_key, JWT_ALGORITHM)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
httpsensible-0.2.2 lib/httpsensible/jwt.rb
httpsensible-0.2.1 lib/httpsensible/jwt.rb
httpsensible-0.2.0 lib/httpsensible/jwt.rb
httpsensible-0.1.2 lib/httpsensible/jwt.rb
httpsensible-0.1.1 lib/httpsensible/jwt.rb