How vapor/auth works
Project type and purpose
• This is a Swift package named “Auth” that provides authentication middleware and protocols for Vapor 3 applications. It is not a standalone server or end-user app but a library module you plug into your Vapor web service to handle user authentication via multiple strategies (Basic, Bearer, Header, Password, Token, Session-persisted).
File structure
• Top-level
• Package.swift – SwiftPM manifest
• README.md, CONTRIBUTING.md, circle.yml
• Sources/Authentication – root of the library
• Tests/AuthenticationTests – unit tests
• Sources/Authentication subdirectories
• Core protocols and types:
– Authenticatable.swift
– AuthenticationProvider.swift
– AuthenticationCache.swift
– Exports.swift
• Strategy modules:
– Basic/BasicAuthenticatable.swift, BasicAuthenticationMiddleware.swift
– Bearer/BearerAuthenticatable.swift, BearerAuthenticationMiddleware.swift
– Header/HeaderAuthenticatableMiddleware.swift, HeaderValueAuthenticatable.swift
– Password/PasswordAuthenticatable.swift, PasswordVerifier.swift
– Token/TokenAuthenticatable.swift, TokenAuthenticationMiddleware.swift
– Persist/AuthenticationSessionsMiddleware.swift, RedirectMiddleware.swift, SessionAuthenticatable.swift
• Utilities: AuthenticationError.swift, GuardMiddleware.swift
Essential architectural elements
• Detail each strategy’s position in the pipeline
• How the AuthenticationCache intersects with multiple strategies
• Registration step (AuthenticationProvider) at boot time
• Do not over-fragment: group similar strategies visually but call out each for clarity