Module: Warden::JWTAuth::HeaderParser
- Defined in:
- lib/warden/jwt_auth/header_parser.rb
Overview
Helpers to parse token from a request and to a response
Constant Summary collapse
- METHOD =
Method for ‘Authorization` header. 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 ‘env` with token added to the `HTTP_AUTHORIZATION` header.
-
.to_headers(headers, token) ⇒ Hash
Returns a copy of headers with token added in the ‘Authorization` key.
Class Method Details
.from_env(env) ⇒ String?
Parses the token from a rack request
16 17 18 19 20 21 22 |
# File 'lib/warden/jwt_auth/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 `HTTP_AUTHORIZATION` header. Be aware than `env` is not modified in place.
30 31 32 |
# File 'lib/warden/jwt_auth/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/jwt_auth/header_parser.rb', line 40 def self.to_headers(headers, token) headers = headers.dup headers['Authorization'] = "#{METHOD} #{token}" headers end |