123456789_123456789_123456789_123456789_123456789_

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

Instance Method Summary

Instance Method Details

#authenticate_or_request_with_http_token(realm = "Application", message = nil, content_type = nil, scheme: nil, &login_procedure)

Authenticate using an HTTP token, or otherwise render an HTTP header requesting the client to send a token. For the authentication to be considered successful, login_procedure must not return a false value. Typically, the authenticated user is returned.

The optional scheme restricts authentication to that scheme (or any of them, when given an array) and uses it verbatim for the WWW-Authenticate response header. Any scheme name can be required. When no scheme is given, "Token", "Bearer", and "DPoP" are accepted. The request's authentication scheme is yielded as a downcased symbol in an optional third argument to login_procedure.

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

[ GitHub ]

  
# File 'actionpack/lib/action_controller/metal/http_authentication.rb', line 449

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

#authenticate_with_http_token(scheme: nil, &login_procedure)

Authenticate using an HTTP 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.

[ GitHub ]

  
# File 'actionpack/lib/action_controller/metal/http_authentication.rb', line 457

def authenticate_with_http_token(scheme: nil, &)
  Token.authenticate(self, scheme:, &)
end

#request_http_token_authentication(realm = "Application", message = nil, content_type = nil, scheme: nil)

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

[ GitHub ]

  
# File 'actionpack/lib/action_controller/metal/http_authentication.rb', line 463

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