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

10 files changed

+137
-91
lines changed

Package.resolved

+83-46
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"originHash" : "8eae3f1f6b3fdd9e96808f51e14e8cfd76c1d05fce4dfd9d0b99b48a0defcc6c",
23
"pins" : [
34
{
45
"identity" : "anycodable",
@@ -14,8 +15,8 @@
1415
"kind" : "remoteSourceControl",
1516
"location" : "https://github.com/swift-server/async-http-client.git",
1617
"state" : {
17-
"revision" : "864c8d9e0ead5de7ba70b61c8982f89126710863",
18-
"version" : "1.15.0"
18+
"revision" : "333f51104b75d1a5b94cb3b99e4c58a3b442c9f7",
19+
"version" : "1.25.2"
1920
}
2021
},
2122
{
@@ -32,26 +33,17 @@
3233
"kind" : "remoteSourceControl",
3334
"location" : "https://github.com/vapor/console-kit.git",
3435
"state" : {
35-
"revision" : "447f1046fb4e9df40973fe426ecb24a6f0e8d3b4",
36-
"version" : "4.6.0"
37-
}
38-
},
39-
{
40-
"identity" : "jwt",
41-
"kind" : "remoteSourceControl",
42-
"location" : "https://github.com/vapor/jwt.git",
43-
"state" : {
44-
"revision" : "d65f32bfd08fae5910d603028be5dec4f35b3482",
45-
"version" : "4.2.2"
36+
"revision" : "742f624a998cba2a9e653d9b1e91ad3f3a5dff6b",
37+
"version" : "4.15.2"
4638
}
4739
},
4840
{
4941
"identity" : "jwt-kit",
5042
"kind" : "remoteSourceControl",
5143
"location" : "https://github.com/vapor/jwt-kit.git",
5244
"state" : {
53-
"revision" : "ef12bdfa557cd9d9f0c53396e0a9908f773bcd7b",
54-
"version" : "4.9.0"
45+
"revision" : "03f5013f0b547ce43abe45e7e90711303a3e5495",
46+
"version" : "5.1.2"
5547
}
5648
},
5749
{
@@ -68,8 +60,8 @@
6860
"kind" : "remoteSourceControl",
6961
"location" : "https://github.com/vapor/routing-kit.git",
7062
"state" : {
71-
"revision" : "bdc9c25adbf77ba2b02113077ae8f355d87df83e",
72-
"version" : "4.7.1"
63+
"revision" : "8c9a227476555c55837e569be71944e02a056b72",
64+
"version" : "4.9.1"
7365
}
7466
},
7567
{
@@ -81,103 +73,130 @@
8173
"version" : "1.0.0"
8274
}
8375
},
76+
{
77+
"identity" : "swift-asn1",
78+
"kind" : "remoteSourceControl",
79+
"location" : "https://github.com/apple/swift-asn1.git",
80+
"state" : {
81+
"revision" : "ae33e5941bb88d88538d0a6b19ca0b01e6c76dcf",
82+
"version" : "1.3.1"
83+
}
84+
},
8485
{
8586
"identity" : "swift-atomics",
8687
"kind" : "remoteSourceControl",
8788
"location" : "https://github.com/apple/swift-atomics.git",
8889
"state" : {
89-
"revision" : "ff3d2212b6b093db7f177d0855adbc4ef9c5f036",
90-
"version" : "1.0.3"
90+
"revision" : "cd142fd2f64be2100422d658e7411e39489da985",
91+
"version" : "1.2.0"
9192
}
9293
},
9394
{
94-
"identity" : "swift-backtrace",
95+
"identity" : "swift-certificates",
9596
"kind" : "remoteSourceControl",
96-
"location" : "https://github.com/swift-server/swift-backtrace.git",
97+
"location" : "https://github.com/apple/swift-certificates.git",
9798
"state" : {
98-
"revision" : "f25620d5d05e2f1ba27154b40cafea2b67566956",
99-
"version" : "1.3.3"
99+
"revision" : "274f8668d3ec5d2892904d8465635c5ea659f767",
100+
"version" : "1.7.0"
100101
}
101102
},
102103
{
103104
"identity" : "swift-collections",
104105
"kind" : "remoteSourceControl",
105106
"location" : "https://github.com/apple/swift-collections.git",
106107
"state" : {
107-
"revision" : "937e904258d22af6e447a0b72c0bc67583ef64a2",
108-
"version" : "1.0.4"
108+
"revision" : "671108c96644956dddcd89dd59c203dcdb36cec7",
109+
"version" : "1.1.4"
109110
}
110111
},
111112
{
112113
"identity" : "swift-crypto",
113114
"kind" : "remoteSourceControl",
114115
"location" : "https://github.com/apple/swift-crypto.git",
115116
"state" : {
116-
"revision" : "da0fe44138ab86e380f40a2acbd8a611b07d3f64",
117-
"version" : "2.4.0"
117+
"revision" : "45305d32cfb830faebcaa9a7aea66ad342637518",
118+
"version" : "3.11.1"
119+
}
120+
},
121+
{
122+
"identity" : "swift-distributed-tracing",
123+
"kind" : "remoteSourceControl",
124+
"location" : "https://github.com/apple/swift-distributed-tracing.git",
125+
"state" : {
126+
"revision" : "a64a0abc2530f767af15dd88dda7f64d5f1ff9de",
127+
"version" : "1.2.0"
128+
}
129+
},
130+
{
131+
"identity" : "swift-http-types",
132+
"kind" : "remoteSourceControl",
133+
"location" : "https://github.com/apple/swift-http-types",
134+
"state" : {
135+
"revision" : "ef18d829e8b92d731ad27bb81583edd2094d1ce3",
136+
"version" : "1.3.1"
118137
}
119138
},
120139
{
121140
"identity" : "swift-log",
122141
"kind" : "remoteSourceControl",
123142
"location" : "https://github.com/apple/swift-log.git",
124143
"state" : {
125-
"revision" : "32e8d724467f8fe623624570367e3d50c5638e46",
126-
"version" : "1.5.2"
144+
"revision" : "96a2f8a0fa41e9e09af4585e2724c4e825410b91",
145+
"version" : "1.6.2"
127146
}
128147
},
129148
{
130149
"identity" : "swift-metrics",
131150
"kind" : "remoteSourceControl",
132151
"location" : "https://github.com/apple/swift-metrics.git",
133152
"state" : {
134-
"revision" : "e8bced74bc6d747745935e469f45d03f048d6cbd",
135-
"version" : "2.3.4"
153+
"revision" : "5e63558d12e0267782019f5dadfcae83a7d06e09",
154+
"version" : "2.5.1"
136155
}
137156
},
138157
{
139158
"identity" : "swift-nio",
140159
"kind" : "remoteSourceControl",
141160
"location" : "https://github.com/apple/swift-nio.git",
142161
"state" : {
143-
"revision" : "9b2848d76f5caad08b97e71a04345aa5bdb23a06",
144-
"version" : "2.49.0"
162+
"revision" : "c51907a839e63ebf0ba2076bba73dd96436bd1b9",
163+
"version" : "2.81.0"
145164
}
146165
},
147166
{
148167
"identity" : "swift-nio-extras",
149168
"kind" : "remoteSourceControl",
150169
"location" : "https://github.com/apple/swift-nio-extras.git",
151170
"state" : {
152-
"revision" : "cc1e5275079380c859417dbea8588531f1a90ec3",
153-
"version" : "1.18.0"
171+
"revision" : "2e9746cfc57554f70b650b021b6ae4738abef3e6",
172+
"version" : "1.24.1"
154173
}
155174
},
156175
{
157176
"identity" : "swift-nio-http2",
158177
"kind" : "remoteSourceControl",
159178
"location" : "https://github.com/apple/swift-nio-http2.git",
160179
"state" : {
161-
"revision" : "38feec96bcd929028939107684073554bf01abeb",
162-
"version" : "1.25.2"
180+
"revision" : "170f4ca06b6a9c57b811293cebcb96e81b661310",
181+
"version" : "1.35.0"
163182
}
164183
},
165184
{
166185
"identity" : "swift-nio-ssl",
167186
"kind" : "remoteSourceControl",
168187
"location" : "https://github.com/apple/swift-nio-ssl.git",
169188
"state" : {
170-
"revision" : "4fb7ead803e38949eb1d6fabb849206a72c580f3",
171-
"version" : "2.23.0"
189+
"revision" : "0cc3528ff48129d64ab9cab0b1cd621634edfc6b",
190+
"version" : "2.29.3"
172191
}
173192
},
174193
{
175194
"identity" : "swift-nio-transport-services",
176195
"kind" : "remoteSourceControl",
177196
"location" : "https://github.com/apple/swift-nio-transport-services.git",
178197
"state" : {
179-
"revision" : "c0d9a144cfaec8d3d596aadde3039286a266c15c",
180-
"version" : "1.15.0"
198+
"revision" : "3c394067c08d1225ba8442e9cffb520ded417b64",
199+
"version" : "1.23.1"
181200
}
182201
},
183202
{
@@ -189,24 +208,42 @@
189208
"version" : "1.0.2"
190209
}
191210
},
211+
{
212+
"identity" : "swift-service-context",
213+
"kind" : "remoteSourceControl",
214+
"location" : "https://github.com/apple/swift-service-context.git",
215+
"state" : {
216+
"revision" : "8946c930cae601452149e45d31d8ddfac973c3c7",
217+
"version" : "1.2.0"
218+
}
219+
},
220+
{
221+
"identity" : "swift-system",
222+
"kind" : "remoteSourceControl",
223+
"location" : "https://github.com/apple/swift-system.git",
224+
"state" : {
225+
"revision" : "a34201439c74b53f0fd71ef11741af7e7caf01e1",
226+
"version" : "1.4.2"
227+
}
228+
},
192229
{
193230
"identity" : "vapor",
194231
"kind" : "remoteSourceControl",
195232
"location" : "https://github.com/vapor/vapor.git",
196233
"state" : {
197-
"revision" : "f39218ec4998654c59251b282cbf4bb9b2cf2629",
198-
"version" : "4.74.2"
234+
"revision" : "a425e32f9b9d19c0ecab952cb4484c1c15e2536f",
235+
"version" : "4.113.2"
199236
}
200237
},
201238
{
202239
"identity" : "websocket-kit",
203240
"kind" : "remoteSourceControl",
204241
"location" : "https://github.com/vapor/websocket-kit.git",
205242
"state" : {
206-
"revision" : "2b8885974e8d9f522e787805000553f4f7cce8a0",
207-
"version" : "2.7.0"
243+
"revision" : "4232d34efa49f633ba61afde365d3896fc7f8740",
244+
"version" : "2.15.0"
208245
}
209246
}
210247
],
211-
"version" : 2
248+
"version" : 3
212249
}

Package.swift

+4-4
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

+11-6
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)