Module: ActionController::HttpAuthentication::Token::ControllerMethods

Included in:
Base
Defined in:
lib/action_controller/metal/http_authentication.rb

Instance Method Summary collapse

Instance Method Details

#authenticate_or_request_with_http_token(realm = "Application", message = nil, &login_procedure) ⇒ Object

Authenticate using an HTTP Bearer token, or otherwise render an HTTP header requesting the client to send a Bearer token. For the authentication to be considered successful, ‘login_procedure` should return a non-nil value. Typically, the authenticated user is returned.

See ActionController::HttpAuthentication::Token for example usage.



438
439
440
# File 'lib/action_controller/metal/http_authentication.rb', line 438

def authenticate_or_request_with_http_token(realm = "Application", message = nil, &)
  authenticate_with_http_token(&) || request_http_token_authentication(realm, message)
end

#authenticate_with_http_token(&login_procedure) ⇒ Object

Authenticate using an HTTP Bearer token. Returns the return value of ‘login_procedure` if a token is found. Returns `nil` if no token is found.

See ActionController::HttpAuthentication::Token for example usage.



446
447
448
# File 'lib/action_controller/metal/http_authentication.rb', line 446

def authenticate_with_http_token(&)
  Token.authenticate(self, &)
end

#request_http_token_authentication(realm = "Application", message = nil) ⇒ Object

Render an HTTP header requesting the client to send a Bearer token for authentication.



452
453
454
# File 'lib/action_controller/metal/http_authentication.rb', line 452

def request_http_token_authentication(realm = "Application", message = nil)
  Token.authentication_request(self, realm, message)
end