|
|
|
@@ -2,28 +2,23 @@ import NIOSSL |
|
|
|
import Fluent |
|
|
|
import FluentPostgresDriver |
|
|
|
import Vapor |
|
|
|
import JWT |
|
|
|
|
|
|
|
extension String { |
|
|
|
var bytes: [UInt8] { .init(self.utf8) } |
|
|
|
} |
|
|
|
|
|
|
|
extension JWKIdentifier { |
|
|
|
static let `public` = JWKIdentifier(string: "public") |
|
|
|
static let `private` = JWKIdentifier(string: "private") |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// configures your application |
|
|
|
public func configure(_ app: Application) async throws { |
|
|
|
|
|
|
|
let privateKey = try String(contentsOfFile: app.directory.workingDirectory + "jwtRS256.key") |
|
|
|
let privateSigner = try JWTSigner.rs256(key: .private(pem: privateKey.bytes)) |
|
|
|
|
|
|
|
let publicKey = try String(contentsOfFile: app.directory.workingDirectory + "jwtRS256.key.pub") |
|
|
|
let publicSigner = try JWTSigner.rs256(key: .public(pem: publicKey.bytes)) |
|
|
|
|
|
|
|
app.jwt.signers.use(privateSigner, kid: .private) |
|
|
|
app.jwt.signers.use(publicSigner, kid: .public, isDefault: true) |
|
|
|
// let privateKey = try String(contentsOfFile: app.directory.workingDirectory + "jwtRS256.key") |
|
|
|
// let privateSigner = try JWTSigner.rs256(key: .private(pem: privateKey.bytes)) |
|
|
|
// |
|
|
|
// let publicKey = try String(contentsOfFile: app.directory.workingDirectory + "jwtRS256.key.pub") |
|
|
|
// let publicSigner = try JWTSigner.rs256(key: .public(pem: publicKey.bytes)) |
|
|
|
// |
|
|
|
// app.jwt.signers.use(privateSigner, kid: .private) |
|
|
|
// app.jwt.signers.use(publicSigner, kid: .public, isDefault: true) |
|
|
|
|
|
|
|
app.middleware.use(CORSMiddleware()) |
|
|
|
let corsConfiguration = CORSMiddleware.Configuration( |
|
|
|
|