Module: SolidusJwt::Encodeable
- Included in:
- SolidusJwt
- Defined in:
- lib/solidus_jwt/concerns/encodeable.rb
Instance Method Summary collapse
-
#encode(payload:, expires_in: nil) ⇒ String
Encode a specified payload.
Instance Method Details
#encode(payload:, expires_in: nil) ⇒ String
Encode a specified payload
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/solidus_jwt/concerns/encodeable.rb', line 25 def encode(payload:, expires_in: nil) jwt_payload = payload.dup.with_indifferent_access current_time = Time.current.to_i # @see https://github.com/jwt/ruby-jwt#support-for-reserved-claim-names jwt_payload[:exp] ||= current_time + expires_in.to_i if expires_in.present? jwt_payload[:iat] ||= current_time jwt_payload[:iss] ||= 'solidus' JWT.encode(jwt_payload, SolidusJwt::Config.jwt_secret, SolidusJwt::Config.jwt_algorithm) end |