Credentials
public class Credentials : RouterMiddleware
A pluggable framework for validating user credentials.
-
The dictionary of options to pass to the plugins.
Declaration
Swift
public var options: [String : Any]
-
Initialize a
Credentials
instance.Declaration
Swift
public convenience init()
-
Initialize a
Credentials
instance.Declaration
Swift
public init(options: [String : Any])
Parameters
options
The dictionary of options to pass to the plugins.
-
Handle an incoming request: authenticate the request using the registered plugins.
Declaration
Swift
public func handle(request: RouterRequest, response: RouterResponse, next: @escaping () -> Void)
Parameters
request
The
RouterRequest
object used to get information about the request.response
The
RouterResponse
object used to respond to the request.next
The closure to invoke to enable the Router to check for other handlers or middleware to work with this request.
-
Get the URL to which the flow will return to after successfully authenticating using a redirecting plugin.
Note
By default, it is set to
request.originalURL
.Declaration
Swift
public static func getRedirectingReturnTo(for request: RouterRequest) -> String?
Return Value
A String containing the URL, or nil if there is no session or the URL is not set.
-
Set the URL to which the flow will return to after successfully authenticating using a redirecting plugin.
Note
By default, it is set to
request.originalURL
.Declaration
Swift
public static func setRedirectingReturnTo(_ returnTo: String, for request: RouterRequest)
-
Register a plugin implementing
CredentialsPluginProtocol
.Declaration
Swift
public func register(plugin: CredentialsPluginProtocol)
Parameters
plugin
An implementation of
CredentialsPluginProtocol
. The credentials framework invokes registered plugins to authenticate incoming requests. -
Create a
RouterHandler
that invokes the specific redirecting plugin to authenticate incoming requests.Declaration
Swift
public func authenticate(credentialsType: String, successRedirect: String? = nil, failureRedirect: String? = nil) -> RouterHandler
Parameters
credentialsType
The name of a registered redirecting plugin that will be used for request authentication.
successRedirect
The path to redirect to if the authentication is successful.
failureRedirect
The path to redirect to if the authentication failed.
Return Value
A
RouterHandler
for request authentication. -
Delete the user profile information from the session and the request.
Declaration
Swift
public func logOut(request: RouterRequest)
Parameters
request
The
RouterRequest
object used to get information about the request.