class Dwarf::Proxy
- Dwarf::Proxy
- Reference
- Object
Defined in:
dwarf/proxy.crConstructors
Instance Method Summary
-
#authenticate(scope : String | Nil = nil, strategies = [] of String, raise_exception = false) : JSON::Any | Nil
Run the authentication strategies for the given strategies.
-
#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 -
#authenticate?(scope : String | Nil = nil, strategies = [] of String, &)
Same API as
#authenticated?
but returns a block -
#authenticate?(scope : String | Nil = nil, strategies = [] of String)
Same API as
authenticated
, but returns a boolean instead of a user. -
#authenticated?(scope = retrieve_scope, &)
Same as
#authenticated?
, but return with a block is given -
#authenticated?(scope = retrieve_scope)
Check to see if there is an authenticated user for the given scope.
-
#clear_strategies_cache!(scope : String | Nil = nil, strategies = [] of String)
Clear the cache of performed strategies so far.
- #config : Dwarf::Config
- #context : HTTP::Server::Context
-
#custom_response
Proxy through to the winning strategy to get the custom_response that was generated.
- #default_strategies(*args, **options)
- #default_strategies(*args, **options, &)
-
#headers : HTTP::Headers | Nil
Proxy through to the winning strategy to get the headers that was generated.
-
#lock!
Locks the proxy so new users cannot authenticate during the request lifecycle.
-
#logout
TODO dependence session
- #manager : Dwarf::Manager
-
#message : String | Nil
Proxy through to the winning strategy to get the message that was generated.
-
#result : Dwarf::Strategies::Result | Nil
Proxy through to the winning strategy to get the result.
- #session_serializer : Dwarf::SessionSerializer
-
#set_user(user : JSON::Any, scope : String | Nil = nil) : JSON::Any
Manually set the user auth proxy TODO: store it into session
-
#status : Int32 | Nil
Proxy through to the winning strategy to get the status that was generated.
- #strategies : Hash(String, Hash(String, Dwarf::Strategies::Base | Nil))
-
#unauthenticated?(scope = retrieve_scope, &)
Same as
#authenticated?
, but return with a block is given -
#unauthenticated?(scope = retrieve_scope)
Check to see if there is an authenticated user for the given scope.
-
#user(scope : String | Nil = nil) : JSON::Any | Nil
Provides access to the user json's object in a given scope for a request.
-
#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! - #winning_strategies : Hash(String, Dwarf::Strategies::Base)
- #winning_strategy : Dwarf::Strategies::Base | Nil
- #winning_strategy=(winning_strategy : Dwarf::Strategies::Base | Nil)
Constructor Detail
Instance Method Detail
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("")
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
Same API as #authenticated?
but returns a block
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.
Same as #authenticated?
, but return with a block is given
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?.
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"])
Proxy through to the winning strategy to get the custom_response that was generated.
Proxy through to the winning strategy to get the headers that was generated.
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.
Proxy through to the winning strategy to get the message that was generated.
Proxy through to the winning strategy to get the result.
Manually set the user auth proxy
TODO store it into session
Proxy through to the winning strategy to get the status that was generated.
Same as #authenticated?
, but return with a block is given
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?.
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