AuthModifier
public class AuthModifier<
A: AuthEndpoint,
U: CorvusModelAuthenticatable>:
RestModifier<A>, AuthEndpoint
A class that wraps a component which utilizes an .auth()
modifier. That
allows Corvus to chain modifiers, as it gets treated as any other struct
conforming to AuthEndpoint
. Requires an object U
that represents the
user to authorize.
-
The
KeyPath
to the user property of theQuerySubject
which is to be authenticated.Declaration
Swift
public typealias UserKeyPath = KeyPath< QuerySubject, QuerySubject.Parent<U> >
-
The path to the property to authenticate for.
Declaration
Swift
public let userKeyPath: UserKeyPath
-
Initializes the modifier with its underlying
QueryEndpoint
and itsauth
path, which is the keypath to the property to run authorization for.Declaration
Swift
public init(_ authEndpoint: A, user: UserKeyPath)
Parameters
queryEndpoint
The
QueryEndpoint
which the modifer is attached to.user
A
KeyPath
which leads to the property to authenticate for.operationType
The HTTP method of the wrapped component.
-
A method which checks if the user
U
supplied in theRequest
is equal to the user belonging to the particularQuerySubject
.Throws
AnAbort
error if an item is not found.Declaration
Swift
override public func handler(_ req: Request) throws -> EventLoopFuture<Element>
Parameters
req
An incoming
Request
.Return Value
An
EventLoopFuture
containing an eagerloaded value as defined byElement
. If authorization fails or a user is not found, HTTP.unauthorized
and.notFound
are thrown respectively.