Sha256: 891f9e7e32604caae52c8b577ac776d00d6219bc26e871d3dc653ef409f5adf2

Contents?: true

Size: 872 Bytes

Versions: 2

Compression:

Stored size: 872 Bytes

Contents

require "doorkeeper-jwt/version"
require "doorkeeper-jwt/config"
require 'jwt'

module Doorkeeper
  module JWT
    def self.generate(opts = {})
      ::JWT.encode(
        token_payload(opts),
        secret_key,
        encryption_method
      )
    end

  private

    def self.token_payload(opts = {})
      Doorkeeper::JWT.configuration.token_payload.call opts
    end

    def self.secret_key
      secret_key_file || Doorkeeper::JWT.configuration.secret_key
    end

    def self.secret_key_file
      return nil if Doorkeeper::JWT.configuration.secret_key_path.nil?
      OpenSSL::PKey::RSA.new(
        File.open(Doorkeeper::JWT.configuration.secret_key_path)
      )
    end

    def self.encryption_method
      return nil unless Doorkeeper::JWT.configuration.encryption_method
      Doorkeeper::JWT.configuration.encryption_method.to_s.upcase
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
doorkeeper-jwt-0.1.3 lib/doorkeeper-jwt.rb
doorkeeper-jwt-0.1.1 lib/doorkeeper-jwt.rb