Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
as_jwt_auth / lib / as_jwt_auth / verify_jwt.rb
Size: Mime:
require 'jwt'

module AsJWTAuth
  class VerifyJWT
    def self.call(string)
      new.valid? string
    end

    def initialize(public_key)
      @public_key = public_key
    end

    def valid?(string)
      JWT.decode string, public_key, true, jwt_options
    rescue JWT::DecodeError
      false
    end

    private

    attr_reader :public_key

    def jwt_options
      { algorithm: 'ES256' }
    end

    # TODO: Comment on using this in the future
    # aud: expected_audience, verify_aud: true

  end
end