From 0ced236587fcfebe038996dad627bb9910f4ed13 Mon Sep 17 00:00:00 2001 From: Bruno Antunes Date: Mon, 9 Sep 2024 11:38:05 +0100 Subject: [PATCH] raw_header support, version bump --- lib/warden/jwt_auth.rb | 6 ++++++ lib/warden/jwt_auth/header_parser.rb | 8 ++++++-- lib/warden/jwt_auth/version.rb | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/warden/jwt_auth.rb b/lib/warden/jwt_auth.rb index 21026a7..4f11be3 100644 --- a/lib/warden/jwt_auth.rb +++ b/lib/warden/jwt_auth.rb @@ -142,6 +142,12 @@ def self.jwks default: nil, constructor: ->(value) { init_jkws_loader(value) }) + # If JWT header should be parsed "raw" ie without `Bearer xxxxx` and just `xxxxx` + # + # @example + # [true] + setting(:raw_header, default: false) + Import = Dry::AutoInject(config) end end diff --git a/lib/warden/jwt_auth/header_parser.rb b/lib/warden/jwt_auth/header_parser.rb index e04c45c..11420d0 100644 --- a/lib/warden/jwt_auth/header_parser.rb +++ b/lib/warden/jwt_auth/header_parser.rb @@ -17,8 +17,12 @@ def self.from_env(env) auth = EnvHelper.authorization_header(env) return nil unless auth - method, token = auth.split - method == METHOD ? token : nil + if JWTAuth.config.raw_header + auth + else + method, token = auth.split + method == METHOD ? token : nil + end end # Returns a copy of `env` with token added to the header configured through diff --git a/lib/warden/jwt_auth/version.rb b/lib/warden/jwt_auth/version.rb index 27cee1f..2da5f37 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.3' + VERSION = '0.12.4' end end