Sha256: 59322a57f7e34a2d4f34b413e130b9b2170134015d9d81c54573621d8f28031b
Contents?: true
Size: 626 Bytes
Versions: 4
Compression:
Stored size: 626 Bytes
Contents
module ApiPack class JsonWebToken # exp: 24 hours from now def self.encode(payload, exp: (Time.now + 1 * 86_400).to_i) raise ApiPack::Errors::Auth::MissingHmacSecret if ApiPack.hmac_secret.nil? payload[:exp] = exp.to_i JWT.encode(payload, ApiPack.hmac_secret) rescue ApiPack::Errors::Auth::MissingHmacSecret raise ApiPack::Errors::Auth::MissingHmacSecret, 'ApiPach.hmac_secret is missing' end def self.decode(token) JWT.decode(token, ApiPack.hmac_secret).first rescue JWT::DecodeError => e raise ApiPack::Errors::Auth::InvalidToken, e.message end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
api_pack-1.3.1 | lib/api_pack/json_web_token.rb |
api_pack-1.2.1 | lib/api_pack/json_web_token.rb |
api_pack-1.1.4 | lib/api_pack/json_web_token.rb |
api_pack-1.1.3 | lib/api_pack/json_web_token.rb |