Module: Digestive::Auth

Defined in:
lib/digestive/auth.rb,
lib/digestive/auth/service.rb

Defined Under Namespace

Classes: Service

Instance Method Summary collapse

Instance Method Details

#authenticate(options = {}, &strategy) ⇒ Object

Convenience method to require authentication. If successful, will set the @current_user instance variable of the including object to the authenticated user.

Parameters:

  • options (Hash) (defaults to: {})
  • strategy (Block)

    A block, accepting a single argument, intended to be the authenticating user, which will return true or false to indicate authorization.

Options Hash (options):

  • credentialed (Object)

    An object responding to constant DIGEST_REALM and method find_by_username. See User, to which the option defaults.

  • provider (Object)

    An object responding to methods ‘authenticate_with_http_digest` and `request_http_digest_authentication`. Defaults to nil; if not given, Service will expect the methods to be mixed-in, which in the context of Rails, they should be.

Returns:

  • (Object)

    The authenticated user, or nil if authentication fails.



29
30
31
32
33
34
35
# File 'lib/digestive/auth.rb', line 29

def authenticate(options={}, &strategy)
  credentialed = options[:credentialed] || ::User
  provider = options[:provider]
  service = Service.new(credentialed, provider)
  service.authenticate(&strategy)
  @current_user = service.user
end