class Dwarf::Proxy

Defined in:

dwarf/proxy.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(context : HTTP::Server::Context, manager : Dwarf::Manager = Dwarf::Manager.new) #

[View source]

Instance Method Detail

def authenticate(scope : String | Nil = nil, strategies = [] of String, raise_exception = false) : JSON::Any | Nil #

Run the authentication strategies for the given strategies. If there is already a user logged in for a given scope, the strategies are not run This does not halt the flow of control and is a passive attempt to authenticate only When scope is not specified, the default_scope is assumed.

context.dwarf.authenticate("")

[View source]
def authenticate!(scope : String | Nil = nil, strategies = [] of String) #

The same as #authenticate except on failure it will throw an :warden symbol causing the request to be halted and rendered through the failure_app

context.dwarf.authenticate!(:password, :scope => :publisher) # raise a Dwarf::Error if it cannot authenticate

[View source]
def authenticate?(scope : String | Nil = nil, strategies = [] of String, &) #

Same API as #authenticated? but returns a block


[View source]
def authenticate?(scope : String | Nil = nil, strategies = [] of String) #

Same API as authenticated, but returns a boolean instead of a user. The difference between this method (authenticate?) and authenticated? is that the former will run strategies if the user has not yet been authenticated, and the second relies on already performed ones.


[View source]
def authenticated?(scope = retrieve_scope, &) #

Same as #authenticated?, but return with a block is given


[View source]
def authenticated?(scope = retrieve_scope) #

Check to see if there is an authenticated user for the given scope. This brings the user from the session, but does not run strategies before doing so. If you want strategies to be run, please check authenticate?.


[View source]
def clear_strategies_cache!(scope : String | Nil = nil, strategies = [] of String) #

Clear the cache of performed strategies so far. Warden runs each strategy just once during the request lifecycle. You can clear the strategies cache if you want to allow a strategy to be run more than once.

# Clear all strategies for the configured default_scope
context.dwarf.clear_strategies_cache!
# Clear all strategies for the :admin scope
context.dwarf.clear_strategies_cache!(scope: "admin")

# Clear password strategy for the :admin scope
context.dwarf.clear_strategies_cache!(scope: "admin", strategies: ["password"])

[View source]
def config : Dwarf::Config #

[View source]
def context : HTTP::Server::Context #

[View source]
def custom_response #

Proxy through to the winning strategy to get the custom_response that was generated.


[View source]
def default_strategies(*args, **options) #

[View source]
def default_strategies(*args, **options, &) #

[View source]
def headers : HTTP::Headers | Nil #

Proxy through to the winning strategy to get the headers that was generated.


[View source]
def lock! #

Locks the proxy so new users cannot authenticate during the request lifecycle. This is useful when the request cannot be verified (for example, using a CSRF verification token). Notice that already authenticated users are kept as so.


[View source]
def logout #

TODO dependence session


[View source]
def manager : Dwarf::Manager #

[View source]
def message : String | Nil #

Proxy through to the winning strategy to get the message that was generated.


[View source]
def result : Dwarf::Strategies::Result | Nil #

Proxy through to the winning strategy to get the result.


[View source]
def session_serializer : Dwarf::SessionSerializer #

[View source]
def set_user(user : JSON::Any, scope : String | Nil = nil) : JSON::Any #

Manually set the user auth proxy

TODO store it into session


[View source]
def status : Int32 | Nil #

Proxy through to the winning strategy to get the status that was generated.


[View source]
def strategies : Hash(String, Hash(String, Dwarf::Strategies::Base | Nil)) #

[View source]
def unauthenticated?(scope = retrieve_scope, &) #

Same as #authenticated?, but return with a block is given


[View source]
def unauthenticated?(scope = retrieve_scope) #

Check to see if there is an authenticated user for the given scope. This brings the user from the session, but does not run strategies before doing so. If you want strategies to be run, please check authenticate?.


[View source]
def user(scope : String | Nil = nil) : JSON::Any | Nil #

Provides access to the user json's object in a given scope for a request. Will be nil if not logged in. Please notice that this method does not perform strategies.

# get default user(without scope)
if user = context.dwarf.user
  # do something
end

# with scope
if user = context.dwarf.user("admin")
  # do something
end

[View source]
def user!(scope : String | Nil = nil) : JSON::Any #

Same as #user, but return the user force to be not nil

# get default user(without scope)
context.dwarf.user!

# with scope
context.dwarf.user("admin")!

[View source]
def winning_strategies : Hash(String, Dwarf::Strategies::Base) #

[View source]
def winning_strategy : Dwarf::Strategies::Base | Nil #

[View source]
def winning_strategy=(winning_strategy : Dwarf::Strategies::Base | Nil) #

[View source]