Skip to content

Commit

Permalink
Adding rails-semantic-logger as dependency, version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
sardaukar committed Sep 16, 2024
1 parent 0ced236 commit 455479c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
13 changes: 6 additions & 7 deletions lib/warden/jwt_auth/strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ module JWTAuth
# Warden strategy to authenticate an user through a JWT token in the
# `Authorization` request header
class Strategy < Warden::Strategies::Base
include SemanticLogger::Loggable

def valid?
token_exists? && issuer_claim_valid?
end
Expand All @@ -19,16 +21,13 @@ def authenticate!
aud = EnvHelper.aud_header(env)
user = UserDecoder.new.call(token, scope, aud)

if defined?(::Rails) && user
::Rails.logger.warn("JWT accepted for user #{user.id}")
end
logger.warn("JWT accepted", user: user.id) if user

success!(user)
rescue JWT::DecodeError => e
if defined?(::Rails)
::Rails.logger.warn("JWT decoding failed #{e.message}")
end
fail!(e.message)
logger.error("JWT decoding failed", message: e.message)

fail!(e.message)
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/warden/jwt_auth/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Warden
module JWTAuth
VERSION = '0.12.4'
VERSION = '0.12.5'
end
end
2 changes: 2 additions & 0 deletions warden-jwt_auth.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Gem::Specification.new do |spec|
spec.add_dependency 'warden', '~> 1.2'
# for JWKS caching
spec.add_dependency 'rails', '~> 6'
# for logging
spec.add_dependency 'rails_semantic_logger', '~> 4.12'

spec.add_development_dependency 'bundler'
spec.add_development_dependency 'pry-byebug', '~> 3.7'
Expand Down

0 comments on commit 455479c

Please sign in to comment.