From 455479c63c3bc735507f6fe242cd080f6445d40d Mon Sep 17 00:00:00 2001 From: Bruno Antunes Date: Mon, 16 Sep 2024 18:24:07 +0100 Subject: [PATCH] Adding rails-semantic-logger as dependency, version bump --- lib/warden/jwt_auth/strategy.rb | 13 ++++++------- lib/warden/jwt_auth/version.rb | 2 +- warden-jwt_auth.gemspec | 2 ++ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/warden/jwt_auth/strategy.rb b/lib/warden/jwt_auth/strategy.rb index 4ebc46d..429212a 100644 --- a/lib/warden/jwt_auth/strategy.rb +++ b/lib/warden/jwt_auth/strategy.rb @@ -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 @@ -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 diff --git a/lib/warden/jwt_auth/version.rb b/lib/warden/jwt_auth/version.rb index 2da5f37..267e186 100644 --- a/lib/warden/jwt_auth/version.rb +++ b/lib/warden/jwt_auth/version.rb @@ -2,6 +2,6 @@ module Warden module JWTAuth - VERSION = '0.12.4' + VERSION = '0.12.5' end end diff --git a/warden-jwt_auth.gemspec b/warden-jwt_auth.gemspec index b6f83f5..b76395f 100644 --- a/warden-jwt_auth.gemspec +++ b/warden-jwt_auth.gemspec @@ -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'