Sha256: 5c58cc656fbca200930da2294e39c77fc6c8a2f0972bdcb988b2e819bc323d2d

Contents?: true

Size: 972 Bytes

Versions: 3

Compression:

Stored size: 972 Bytes

Contents

module RealSavvy
  module JWT
    class ShareToken < AbstractToken

      def self.from_ids(audience_id:, subject_id:)
        self.new(
          ::JWT.encode(
            {aud: audience_id, sub: subject_id}, nil, 'none'
          )
        )
      end

      def to_share_token
        self
      end

      private

      def retrieve_claims
        @claims, @header = ::JWT.decode(
                              token,
                              nil,
                              false,
                            )
      rescue ::JWT::DecodeError => e
        raise ::RealSavvy::JWT::BadCredentials.new(e.message)
      end

      def validate_token
        true
      end

      def standardized_token
        token_parts = @token.split('.')
        header = Base64.urlsafe_encode64({typ:"JWT",alg:"none"}.to_json, padding: false)
        @token = [header, (token_parts.length == 1 ? token_parts[0] : token_parts[1]), nil].join('.')
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
real_savvy-0.0.12 lib/real_savvy/jwt/share_token.rb
real_savvy-0.0.10 lib/real_savvy/jwt/share_token.rb
real_savvy-0.0.9 lib/real_savvy/jwt/share_token.rb