The mixin that adds methods to Strelka::HTTPRequest for authentication/authorization.
The Strelka::AuthProvider the app uses for authentication (if any)
The current session namespace
The current session namespace
Extension callback – add instance variables to extended objects.
# File lib/strelka/httprequest/auth.rb, line 14
def initialize( * )
super
@auth_provider = nil
@authenticated_user = nil
end
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 41
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