class Userbin::JWT
Attributes
header[RW]
payload[RW]
Public Class Methods
new(jwt)
click to toggle source
# File lib/userbin/jwt.rb, line 7 def initialize(jwt) begin raise Userbin::SecurityError, 'Empty JWT' unless jwt @payload = ::JWT.decode(jwt, Userbin.config.api_secret, true) do |header| @header = header.with_indifferent_access Userbin.config.api_secret # used by the 'key finder' in the JWT gem end.with_indifferent_access rescue ::JWT::DecodeError => e raise Userbin::SecurityError.new(e) end end
Public Instance Methods
expired?()
click to toggle source
# File lib/userbin/jwt.rb, line 19 def expired? Time.now.utc > Time.at(@header['exp']).utc end
merge!(payload = {})
click to toggle source
# File lib/userbin/jwt.rb, line 23 def merge!(payload = {}) @payload.merge!(payload) end
to_json()
click to toggle source
# File lib/userbin/jwt.rb, line 27 def to_json @payload end
to_token()
click to toggle source
# File lib/userbin/jwt.rb, line 31 def to_token ::JWT.encode(@payload, Userbin.config.api_secret, "HS256", @header) end