Module: StandardId::BearerTokenExtraction
- Defined in:
- lib/standard_id/bearer_token_extraction.rb
Overview
Bearer token extraction utility.
This module serves two roles:
-
**Class method** (‘BearerTokenExtraction.extract`) — pure extraction logic used by TokenManager in lib/. Lives in lib/ so there is no cross-layer dependency on app/ autoloading.
-
**Controller mixin** (‘include StandardId::BearerTokenExtraction`) —provides `extract_bearer_token` as a private instance method. Conventionally, controller concerns live under app/controllers/concerns/, but this module is co-located with the utility to keep the extraction logic in a single file and avoid the same-constant-name conflict between lib/ and app/ autoloading.
Does not use ActiveSupport::Concern because it has no ‘included` or `class_methods` blocks — it is a plain Ruby module.
Controllers that include StandardId::ApiAuthentication do NOT need this —token extraction is handled internally by the TokenManager.
Class Method Summary collapse
-
.extract(auth_header) ⇒ String?
Extracts the Bearer token from a raw Authorization header value.
Class Method Details
.extract(auth_header) ⇒ String?
Extracts the Bearer token from a raw Authorization header value.
Note: prior to the introduction of this module, TokenManager#bearer_token returned “” for a bare “Bearer ” header. This now returns nil via .presence, which is the correct behavior — downstream JWT parsing receives nil instead of attempting to decode an empty string.
47 48 49 50 51 |
# File 'lib/standard_id/bearer_token_extraction.rb', line 47 def self.extract(auth_header) return unless auth_header&.start_with?("Bearer ") auth_header.split(" ", 2).last.presence end |