Module: Warden::Auth0::HeaderParser
- Defined in:
- lib/warden/auth0/header_parser.rb
Overview
Helpers to parse token from a request and to a response
Constant Summary collapse
- METHOD =
Method for
Authorizationheader. Token is present in request/response headers as ‘Bearer %token%` 'Bearer'
Class Method Summary collapse
-
.from_env(env) ⇒ String?
Parses the token from a rack request.
-
.to_env(env, token) ⇒ Hash
Returns a copy of
envwith token added to the header configured throughtoken_headeroption. -
.to_headers(headers, token) ⇒ Hash
Returns a copy of headers with token added in the
Authorizationkey.
Class Method Details
.from_env(env) ⇒ String?
Parses the token from a rack request
16 17 18 19 20 21 22 |
# File 'lib/warden/auth0/header_parser.rb', line 16 def self.from_env(env) auth = EnvHelper.(env) return nil unless auth method, token = auth.split method == METHOD ? token : nil end |
.to_env(env, token) ⇒ Hash
Returns a copy of env with token added to the header configured through token_header option. Be aware than env is not modified in place.
30 31 32 |
# File 'lib/warden/auth0/header_parser.rb', line 30 def self.to_env(env, token) EnvHelper.(env, "#{METHOD} #{token}") end |
.to_headers(headers, token) ⇒ Hash
Returns a copy of headers with token added in the Authorization key. Be aware that headers is not modified in place
40 41 42 43 44 |
# File 'lib/warden/auth0/header_parser.rb', line 40 def self.to_headers(headers, token) headers = headers.dup headers[Auth0.config.token_header] = "#{METHOD} #{token}" headers end |