| @@ -68,8 +68,8 @@ | |||||
| "kind" : "remoteSourceControl", | "kind" : "remoteSourceControl", | ||||
| "location" : "https://github.com/vapor/jwt-kit.git", | "location" : "https://github.com/vapor/jwt-kit.git", | ||||
| "state" : { | "state" : { | ||||
| "revision" : "e05513b5aec24f88012b6e3034115b6bc915356a", | |||||
| "version" : "4.13.2" | |||||
| "revision" : "c2595b9ad7f512d7f334830b4df1fed6e917946a", | |||||
| "version" : "4.13.4" | |||||
| } | } | ||||
| }, | }, | ||||
| { | { | ||||
| @@ -13,7 +13,7 @@ let package = Package( | |||||
| .package(url: "https://github.com/vapor/fluent.git", from: "4.9.0"), | .package(url: "https://github.com/vapor/fluent.git", from: "4.9.0"), | ||||
| // 🐘 Fluent driver for Postgres. | // 🐘 Fluent driver for Postgres. | ||||
| .package(url: "https://github.com/vapor/fluent-postgres-driver.git", from: "2.8.0"), | .package(url: "https://github.com/vapor/fluent-postgres-driver.git", from: "2.8.0"), | ||||
| .package(url: "https://github.com/vapor/jwt.git", from: "4.0.0-rc.1"), | |||||
| .package(url: "https://github.com/vapor/jwt.git", from: "4.2.2"), | |||||
| ], | ], | ||||
| targets: [ | targets: [ | ||||
| .executableTarget( | .executableTarget( | ||||
| @@ -10,6 +10,7 @@ import Fluent | |||||
| import Vapor | import Vapor | ||||
| import Foundation | import Foundation | ||||
| import FluentKit | import FluentKit | ||||
| import JWT | |||||
| final class mdlAssociate: Model, Content { | final class mdlAssociate: Model, Content { | ||||
| static let schema = "associate" | static let schema = "associate" | ||||
| @@ -42,6 +43,15 @@ final class mdlAssociate: Model, Content { | |||||
| } | } | ||||
| } | } | ||||
| extension mdlAssociate{ | extension mdlAssociate{ | ||||
| struct User: JWTPayload{ | |||||
| var id: Int | |||||
| var email: String | |||||
| var password: String | |||||
| func verify(using signer: JWTSigner) throws{ | |||||
| } | |||||
| } | |||||
| struct Create: AsyncMigration { | struct Create: AsyncMigration { | ||||
| func prepare(on database: Database) async throws { | func prepare(on database: Database) async throws { | ||||
| try await database.schema("associate") | try await database.schema("associate") | ||||
| @@ -2,28 +2,23 @@ import NIOSSL | |||||
| import Fluent | import Fluent | ||||
| import FluentPostgresDriver | import FluentPostgresDriver | ||||
| import Vapor | import Vapor | ||||
| import JWT | |||||
| extension String { | extension String { | ||||
| var bytes: [UInt8] { .init(self.utf8) } | var bytes: [UInt8] { .init(self.utf8) } | ||||
| } | } | ||||
| extension JWKIdentifier { | |||||
| static let `public` = JWKIdentifier(string: "public") | |||||
| static let `private` = JWKIdentifier(string: "private") | |||||
| } | |||||
| // configures your application | // configures your application | ||||
| public func configure(_ app: Application) async throws { | 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()) | app.middleware.use(CORSMiddleware()) | ||||
| let corsConfiguration = CORSMiddleware.Configuration( | let corsConfiguration = CORSMiddleware.Configuration( | ||||
| @@ -13,4 +13,7 @@ func routes(_ app: Application) throws { | |||||
| } | } | ||||
| try baseApp.register(collection: cntrlAssociate()) | try baseApp.register(collection: cntrlAssociate()) | ||||
| try baseApp.register(collection: cntrlDepartment()) | try baseApp.register(collection: cntrlDepartment()) | ||||
| try baseApp.register(collection: cntrlDocument()) | |||||
| try baseApp.register(collection: cntrlDocType()) | |||||
| } | } | ||||