Skip to content

Commit 483670a

Browse files
authored
Swift6 + JWT-kit 5 (#1)
* swift 6 * update JWTKit * update package * cleanup
1 parent 3ae4be6 commit 483670a

File tree

10 files changed

+137
-91
lines changed

10 files changed

+137
-91
lines changed

Package.resolved

Lines changed: 83 additions & 46 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
// swift-tools-version: 5.7
1+
// swift-tools-version: 6.0
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
55

66
let package = Package(
77
name: "Firebase",
88
platforms: [
9-
.macOS(.v10_15)
9+
.macOS(.v13),
1010
],
1111
products: [
1212
// Products define the executables and libraries a package produces, and make them visible to other packages.
@@ -17,17 +17,17 @@ let package = Package(
1717
dependencies: [
1818
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"),
1919
.package(url: "https://github.com/Flight-School/AnyCodable", from: "0.6.7"),
20-
.package(url: "https://github.com/vapor/jwt.git", from: "4.0.0"),
20+
.package(url: "https://github.com/vapor/jwt-kit.git", from: "5.0.0"),
2121
],
2222
targets: [
2323
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
2424
// Targets can depend on other targets in this package, and on products in packages this package depends on.
2525
.target(
2626
name: "Firebase",
2727
dependencies: [
28-
.product(name: "JWT", package: "jwt"),
2928
.product(name: "AnyCodable", package: "AnyCodable"),
3029
.product(name: "Vapor", package: "vapor"),
30+
.product(name: "JWTKit", package: "jwt-kit"),
3131
]),
3232
.testTarget(
3333
name: "FirebaseTests",

Sources/Firebase/ApiClient.swift

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
import Foundation
99
import Vapor
10-
import JWT
10+
import JWTKit
1111

12-
class ApiClient {
12+
actor ApiClient: Sendable {
1313

1414
let app: Application
1515
var config: Config?
@@ -18,6 +18,10 @@ class ApiClient {
1818
self.app = app
1919
}
2020

21+
func setConfig(_ config: Config?) async {
22+
self.config = config
23+
}
24+
2125
func throwIfError(response: ClientResponse) throws {
2226
if let error = try? response.content.decode(FirebaseErrorResponse.self) {
2327
throw error
@@ -60,11 +64,12 @@ class ApiClient {
6064

6165
let scopes = "https://www.googleapis.com/auth/cloud-platform https://www.googleapis.com/auth/datastore https://www.googleapis.com/auth/devstorage.full_control https://www.googleapis.com/auth/firebase https://www.googleapis.com/auth/identitytoolkit https://www.googleapis.com/auth/userinfo.email"
6266

63-
let privateKey = try RSAKey.private(pem: config.private_key)
64-
let signers = JWTSigners()
65-
signers.use(.rs256(key: privateKey), kid: JWKIdentifier(string: config.private_key_id))
67+
let privateKey = try Insecure.RSA.PrivateKey(pem: config.private_key)
68+
let signers = JWTKeyCollection()
69+
70+
await signers.add(rsa: privateKey, digestAlgorithm: .sha256, kid: JWKIdentifier(string: config.private_key_id))
6671

67-
let jwt = try signers.sign(FirebaseAdminAuthPayload(
72+
let jwt = try await signers.sign(FirebaseAdminAuthPayload(
6873
scope: scopes,
6974
issuer: .init(stringLiteral: config.client_email),
7075
audience: .init(stringLiteral: config.token_uri))

0 commit comments

Comments
 (0)