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
Credentialsinstance.Declaration
Swift
public convenience init() -
Initialize a
Credentialsinstance.Declaration
Swift
public init(options: [String : Any])Parameters
optionsThe 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
requestThe
RouterRequestobject used to get information about the request.responseThe
RouterResponseobject used to respond to the request.nextThe 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
pluginAn implementation of
CredentialsPluginProtocol. The credentials framework invokes registered plugins to authenticate incoming requests. -
Create a
RouterHandlerthat invokes the specific redirecting plugin to authenticate incoming requests.Declaration
Swift
public func authenticate(credentialsType: String, successRedirect: String? = nil, failureRedirect: String? = nil) -> RouterHandlerParameters
credentialsTypeThe name of a registered redirecting plugin that will be used for request authentication.
successRedirectThe path to redirect to if the authentication is successful.
failureRedirectThe path to redirect to if the authentication failed.
Return Value
A
RouterHandlerfor request authentication. -
Delete the user profile information from the session and the request.
Declaration
Swift
public func logOut(request: RouterRequest)Parameters
requestThe
RouterRequestobject used to get information about the request.
View on GitHub
Credentials Class Reference