Module: AtomicLti::AuthToken

Defined in:
app/lib/atomic_lti/auth_token.rb

Constant Summary collapse

ALGORITHM =
"HS512".freeze

Class Method Summary collapse

Class Method Details

.decode(token, secret = nil, validate = true, algorithm = ALGORITHM) ⇒ Object



26
27
28
29
30
31
32
33
# File 'app/lib/atomic_lti/auth_token.rb', line 26

def self.decode(token, secret = nil, validate = true, algorithm = ALGORITHM)
  JWT.decode(
    token,
    secret || AtomicLti.jwt_secret,
    validate,
    { algorithm: algorithm },
  )
end

.issue_token(payload, exp = 24.hours.from_now, secret = nil, aud = nil, header_fields = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'app/lib/atomic_lti/auth_token.rb', line 10

def self.issue_token(payload, exp = 24.hours.from_now, secret = nil, aud = nil, header_fields = {})
  payload["iat"] = DateTime.now.to_i    # issued at claim
  payload["exp"] = exp.to_i             # Default expiration set to 24 hours.
  payload["aud"] = aud || Rails.application.secrets.auth0_client_id
  JWT.encode(
    payload,
    secret || AtomicLti.jwt_secret,
    ALGORITHM,
    header_fields,
  )
end

.valid?(token, secret = nil, algorithm = ALGORITHM) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'app/lib/atomic_lti/auth_token.rb', line 22

def self.valid?(token, secret = nil, algorithm = ALGORITHM)
  decode(token, secret, true, algorithm)
end