module Strelka::HTTPRequest::Auth
The mixin that adds methods to Strelka::HTTPRequest
for authentication/authorization.
Attributes
auth_provider[RW]
The Strelka::AuthProvider
the app uses for authentication (if any)
authenticated?[RW]
The current session namespace
authenticated_user[RW]
The current session namespace
Public Class Methods
new( * )
click to toggle source
Extension callback – add instance variables to extended objects.
Calls superclass method
# File lib/strelka/httprequest/auth.rb, line 15 def initialize( * ) super @auth_provider = nil @authenticated_user = nil end
Public Instance Methods
authenticate( options={}, &block )
click to toggle source
Try to authenticate the request using the specified block
. If a block
is not provided, the authenticate
method of the app's AuthProvider is used instead.
Valid options
are:
:optional
-
if this is set to a true value, don't throw a 401 Requires Authentication if the authentication fails.
# File lib/strelka/httprequest/auth.rb, line 42 def authenticate( options={}, &block ) block ||= self.auth_provider.method( :authenticate ) result = block.call( self ) finish_with( HTTP::UNAUTHORIZED, "Authorization failed" ) unless result || options[:optional] self.authenticated_user = result return result end