Class: RailsIam::Authentication::JwtDecoder

Inherits:
RailsIamService show all
Includes:
ConfigLoader
Defined in:
app/services/rails_iam/authentication/jwt_decoder.rb

Defined Under Namespace

Classes: InvalidToken

Instance Method Summary collapse

Methods included from ConfigLoader

#authentication_strategies, #authorization_rule_error, #cookie_options, #jwt_algorithm, #jwt_audience, #jwt_expiry, #jwt_issuer, #jwt_secret_key, #refresh_token_transport, #session_strategy, #user_class

Methods inherited from RailsIamService

call

Constructor Details

#initialize(token, headers = {}) ⇒ JwtDecoder

Returns a new instance of JwtDecoder.



12
13
14
15
16
# File 'app/services/rails_iam/authentication/jwt_decoder.rb', line 12

def initialize(token, headers = {})
  super()
  @token = token
  @headers = headers
end

Instance Method Details

#callObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/services/rails_iam/authentication/jwt_decoder.rb', line 18

def call
  decoded = JWT.decode(
    token,
    jwt_secret_key,
    true,
    { algorithm: jwt_algorithm, verify_jti: true }.merge(headers),
  )

  decoded.first.deep_symbolize_keys
rescue JWT::ExpiredSignature
  raise InvalidToken, token_expired_error
rescue JWT::DecodeError
  raise InvalidToken, token_error
end