-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e631ed
commit f2d3f02
Showing
4 changed files
with
144 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// SecretMiddleware.swift | ||
// PassKit | ||
// | ||
// Created by Francesco Paolo Severino on 09/08/24. | ||
// | ||
|
||
import Vapor | ||
|
||
struct SecretMiddleware: AsyncMiddleware { | ||
let secret: String | ||
|
||
init(secret: String) { | ||
self.secret = secret | ||
} | ||
|
||
func respond(to request: Request, chainingTo next: any AsyncResponder) async throws -> Response { | ||
guard request.headers.first(name: "X-Secret") == secret else { | ||
throw Abort(.unauthorized, reason: "Incorrect X-Secret header.") | ||
} | ||
return try await next.respond(to: request) | ||
} | ||
} |
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,23 @@ | ||
// | ||
// SecretMiddleware.swift | ||
// PassKit | ||
// | ||
// Created by Francesco Paolo Severino on 09/08/24. | ||
// | ||
|
||
import Vapor | ||
|
||
struct SecretMiddleware: AsyncMiddleware { | ||
let secret: String | ||
|
||
init(secret: String) { | ||
self.secret = secret | ||
} | ||
|
||
func respond(to request: Request, chainingTo next: any AsyncResponder) async throws -> Response { | ||
guard request.headers.first(name: "X-Secret") == secret else { | ||
throw Abort(.unauthorized, reason: "Incorrect X-Secret header.") | ||
} | ||
return try await next.respond(to: request) | ||
} | ||
} |