Vapor Documentation

Protocol Authenticatable

public protocol Authenticatable  

Capable of being authenticated.

%469 Authenticatable Authenticatable SessionAuthenticatable SessionAuthenticatable SessionAuthenticatable->Authenticatable

Types Conforming to Authenticatable

SessionAuthenticatable

Models conforming to this protocol can have their authentication status cached using SessionAuthenticator.

Default Implementations

guard​Middleware(throwing:​)

public static func guardMiddleware(
        throwing error: Error = Abort(.unauthorized, reason: "\(Self.self) not authenticated.")
    ) -> Middleware  

This middleware ensures that an Authenticatable type A has been authenticated by a previous Middleware or throws an Error. The middlewares that actually perform authentication will not throw errors if they fail to authenticate the user (except in some exceptional cases like malformed data). This allows the middlewares to be composed together to create chains of authentication for multiple user types.

Use this middleware to protect routes that might not otherwise attempt to access the authenticated user (which always requires prior authentication).

Use Authenticatable.guardMiddleware(...) to create an instance.

Use this middleware in conjunction with other middleware such as BearerAuthenticator and BasicAuthenticator to do the actual authentication.

Parameters

throwing Error

Error to throw if the type is not authed.

redirect​Middleware(path:​)

public static func redirectMiddleware(path: String) -> Middleware  

Basic middleware to redirect unauthenticated requests to the supplied path

Parameters

path String

The path to redirect to if the request is not authenticated

redirect​Middleware(make​Path:​)

public static func redirectMiddleware(makePath: @escaping (Request) -> String) -> Middleware  

Basic middleware to redirect unauthenticated requests to the supplied path

Parameters

make​Path @escaping (Request) -> String

The closure that returns the redirect path based on the given Request object