Module: Scimaenaga::Encoder

Extended by:
Encoder
Included in:
Encoder
Defined in:
lib/scimaenaga/encoder.rb

Instance Method Summary collapse

Instance Method Details

#decode(token) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/scimaenaga/encoder.rb', line 18

def decode(token)
  verify = Scimaenaga.config.signing_algorithm != Scimaenaga::Config::ALGO_NONE

  JWT.decode(token, Scimaenaga.config.signing_secret, verify,
             algorithm: Scimaenaga.config.signing_algorithm).first
rescue JWT::VerificationError, JWT::DecodeError
  raise Scimaenaga::ExceptionHandler::InvalidCredentials
end

#encode(company) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/scimaenaga/encoder.rb', line 7

def encode(company)
  payload = {
    iat: Time.current.to_i,
    Scimaenaga.config.basic_auth_model_searchable_attribute =>
      company.public_send(Scimaenaga.config.basic_auth_model_searchable_attribute),
  }

  JWT.encode(payload, Scimaenaga.config.signing_secret,
             Scimaenaga.config.signing_algorithm)
end