Class: ETokenAuth
- Inherits:
-
Object
- Object
- ETokenAuth
- Defined in:
- lib/e-core/instance/setup/auth.rb
Overview
borrowed from Rails and adapted to Espresso needs
Constant Summary collapse
- TOKEN_REGEX =
/^Token /
- AUTHN_PAIR_DELIMITERS =
/(?:,|;|\t+)/
Instance Method Summary collapse
-
#initialize(controller_instance) ⇒ ETokenAuth
constructor
A new instance of ETokenAuth.
-
#request_token_auth(realm) ⇒ Object
Sets a WWW-Authenticate and halt to let the client know a token is required.
-
#validate_token_auth(&proc) ⇒ Object
If token Authorization header is present, call the given proc with the present token and options.
Constructor Details
#initialize(controller_instance) ⇒ ETokenAuth
Returns a new instance of ETokenAuth.
153 154 155 |
# File 'lib/e-core/instance/setup/auth.rb', line 153 def initialize controller_instance @controller_instance = controller_instance end |
Instance Method Details
#request_token_auth(realm) ⇒ Object
Sets a WWW-Authenticate and halt to let the client know a token is required.
176 177 178 179 180 |
# File 'lib/e-core/instance/setup/auth.rb', line 176 def request_token_auth(realm) @controller_instance.response[EConstants::HEADER__AUTHENTICATE] = \ EUtils.encode_token_auth_credentials(realm: realm.delete('"')) @controller_instance.halt(EConstants::STATUS__PROTECTED, "HTTP Token: Access denied.\n") end |
#validate_token_auth(&proc) ⇒ Object
If token Authorization header is present, call the given proc with the present token and options.
167 168 169 170 |
# File 'lib/e-core/instance/setup/auth.rb', line 167 def validate_token_auth &proc token, = token && token.size > 0 && proc.call(token, ) end |