Update README.md
Swift package for adding API Key requirement to vapor backends.
Requests are expected to have the header api-key.
api-key
public func configure(_ app: Application) throws { app.middleware.use(APIKeyMiddleware(keys: ["123"])) }
See Vapor Docs if wanting to add to individual routes.
The following errors are used by default:
Abort(.badRequest, reason: "Missing api-key.")
Abort(.unauthorized, reason: "Unauthorized api-key.")
To override these errors, assign a delegate to the APIKeyMiddleware. Returning nil uses defaults.
class Delegate: APIKeyMiddlewareDelegate { static let shared = Delegate() init() {} func errorForMissingKey(in middleware: APIKeyMiddleware) -> Error? { Abort(.imATeapot, reason: "Missing api-key was found by teapot.") } func errorForUnauthorizedKey(in middleware: APIKeyMiddleware) -> Error? { Abort(.imATeapot, reason: "Unauthorized api-key was found by teapot.") } } public func configure(_ app: Application) throws { let middleware = APIKeyMiddleware(keys: ["123"], delegate: Delegate.shared) app.middleware.use(middleware) }
Add the following to your project:
https://github.com/ptrkstr/APIKeyMiddleware
Raise an issue if you need these
©Copyright 2023 CCF 开源发展委员会 Powered by Trustie& IntelliDE 京ICP备13000930号
APIKeyMiddleware
Swift package for adding API Key requirement to vapor backends.
Features
Usage
Requests are expected to have the header
api-key
.Simple
See Vapor Docs if wanting to add to individual routes.
Override Errors
The following errors are used by default:
Abort(.badRequest, reason: "Missing api-key.")
Abort(.unauthorized, reason: "Unauthorized api-key.")
To override these errors, assign a delegate to the APIKeyMiddleware. Returning nil uses defaults.
Installation
SPM
Add the following to your project:
Possible Future Features