Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 83 additions & 46 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// swift-tools-version: 5.7
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "Firebase",
platforms: [
.macOS(.v10_15)
.macOS(.v13),
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
Expand All @@ -17,17 +17,17 @@ let package = Package(
dependencies: [
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"),
.package(url: "https://github.com/Flight-School/AnyCodable", from: "0.6.7"),
.package(url: "https://github.com/vapor/jwt.git", from: "4.0.0"),
.package(url: "https://github.com/vapor/jwt-kit.git", from: "5.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "Firebase",
dependencies: [
.product(name: "JWT", package: "jwt"),
.product(name: "AnyCodable", package: "AnyCodable"),
.product(name: "Vapor", package: "vapor"),
.product(name: "JWTKit", package: "jwt-kit"),
]),
.testTarget(
name: "FirebaseTests",
Expand Down
17 changes: 11 additions & 6 deletions Sources/Firebase/ApiClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import Foundation
import Vapor
import JWT
import JWTKit

class ApiClient {
actor ApiClient: Sendable {

let app: Application
var config: Config?
Expand All @@ -18,6 +18,10 @@ class ApiClient {
self.app = app
}

func setConfig(_ config: Config?) async {
self.config = config
}

func throwIfError(response: ClientResponse) throws {
if let error = try? response.content.decode(FirebaseErrorResponse.self) {
throw error
Expand Down Expand Up @@ -60,11 +64,12 @@ class ApiClient {

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"

let privateKey = try RSAKey.private(pem: config.private_key)
let signers = JWTSigners()
signers.use(.rs256(key: privateKey), kid: JWKIdentifier(string: config.private_key_id))
let privateKey = try Insecure.RSA.PrivateKey(pem: config.private_key)
let signers = JWTKeyCollection()

await signers.add(rsa: privateKey, digestAlgorithm: .sha256, kid: JWKIdentifier(string: config.private_key_id))

let jwt = try signers.sign(FirebaseAdminAuthPayload(
let jwt = try await signers.sign(FirebaseAdminAuthPayload(
scope: scopes,
issuer: .init(stringLiteral: config.client_email),
audience: .init(stringLiteral: config.token_uri))
Expand Down
Loading