-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update auth-srp for 2.0 * Clean up look of example a bit, could do more though * Fix test * Update README * Minor changes
- Loading branch information
1 parent
8689ee8
commit dced271
Showing
15 changed files
with
346 additions
and
314 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Hummingbird server framework project | ||
// | ||
// Copyright (c) 2021-2021 the Hummingbird authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import FluentSQLiteDriver | ||
import Hummingbird | ||
import HummingbirdAuth | ||
import HummingbirdFluent | ||
import Logging | ||
|
||
public protocol AppArguments { | ||
var hostname: String { get } | ||
var port: Int { get } | ||
var logLevel: Logger.Level? { get } | ||
var inMemoryDatabase: Bool { get } | ||
var migrate: Bool { get } | ||
} | ||
|
||
func buildApplication(_ args: some AppArguments) async throws -> some ApplicationProtocol { | ||
let logger = { | ||
var logger = Logger(label: "html-form") | ||
logger.logLevel = args.logLevel ?? .info | ||
return logger | ||
}() | ||
let fluent = Fluent(logger: logger) | ||
// add sqlite database | ||
if args.inMemoryDatabase { | ||
fluent.databases.use(.sqlite(.memory), as: .sqlite) | ||
} else { | ||
fluent.databases.use(.sqlite(.file("db.sqlite")), as: .sqlite) | ||
} | ||
// add migrations | ||
await fluent.migrations.add(CreateUser()) | ||
|
||
// set up persist driver before migrate | ||
let persist = await FluentPersistDriver(fluent: fluent) | ||
// Sessions | ||
let sessionStorage = SessionStorage(persist) | ||
|
||
if args.migrate || args.inMemoryDatabase { | ||
try await fluent.migrate() | ||
} | ||
|
||
let router = Router(context: AuthSRPRequestContext.self) | ||
router.middlewares.add(RedirectMiddleware()) | ||
router.middlewares.add(FileMiddleware(logger: logger)) | ||
router.middlewares.add(LogRequestsMiddleware(.info, includeHeaders: true)) | ||
router.addRoutes(UserController(fluent: fluent, sessionStorage: sessionStorage).routes, atPath: "/api/user") | ||
var application = Application( | ||
router: router, | ||
configuration: .init(address: .hostname(args.hostname, port: args.port)), | ||
logger: logger | ||
) | ||
application.addServices(fluent) | ||
return application | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import Hummingbird | ||
import HummingbirdAuth | ||
import Logging | ||
import NIOCore | ||
|
||
struct AuthSRPRequestContext: AuthRequestContext, RequestContext { | ||
var coreContext: CoreRequestContext | ||
var auth: LoginCache | ||
|
||
init(channel: Channel, logger: Logger) { | ||
self.coreContext = .init(allocator: channel.allocator, logger: logger) | ||
self.auth = .init() | ||
} | ||
} |
Oops, something went wrong.