Sha256: 4324f1750443c11cbeda2a02738bf7fa358a85da9c30cef26b83586f2980fd61

Contents?: true

Size: 647 Bytes

Versions: 2

Compression:

Stored size: 647 Bytes

Contents

require 'jwt'

module OpenIDConnect
  class ResponseObject
    class IdToken < ResponseObject
      attr_required :iss, :user_id, :aud, :exp, :secret
      attr_optional :iso29115, :nonce, :issued_to

      def as_json
        (required_attributes + optional_attributes - [:secret]).inject({}) do |hash, key|
          hash.merge! key => self.send(key)
        end.delete_if do |key, value|
          value.nil?
        end
      end

      def to_jwt
        JWT.encode as_json, secret
      end

      def self.from_jwt(jwt, secret)
        new JWT.decode(jwt, secret).with_indifferent_access.merge(:secret => secret)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
openid_connect-0.0.3 lib/openid_connect/response_object/id_token.rb
openid_connect-0.0.2 lib/openid_connect/response_object/id_token.rb