Sha256: 562c3267673f479252eb41767045b2fe0dbc8e9808b5134cb9b2df89c652663e

Contents?: true

Size: 580 Bytes

Versions: 1

Compression:

Stored size: 580 Bytes

Contents

module ApiPack
  class JsonWebToken
    def self.encode(payload, exp: ApiPack.exp)
      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

1 entries across 1 versions & 1 rubygems

Version Path
api_pack-1.1.2 lib/api_pack/json_web_token.rb