Module: Httpsensible::JWT

Defined in:
lib/httpsensible/jwt.rb

Constant Summary collapse

JWT_ALGORITHM =
"RS256"

Class Method Summary collapse

Class Method Details

.encode_jwt(pem, iss, iat: Time.now.to_i - 60, exp: Time.now.to_i + (10 * 60)) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/httpsensible/jwt.rb', line 11

def encode_jwt(pem, iss, iat: Time.now.to_i - 60, exp: Time.now.to_i + (10 * 60))
  private_key = OpenSSL::PKey::RSA.new(pem)
  payload = {
    # issued at time, 60 seconds in the past to allow for clock drift
    iat: iat,
    # JWT expiration time
    exp: exp,
    # Identifier
    iss: iss,
  }

  ::JWT.encode(payload, private_key, JWT_ALGORITHM)
end