Skip to content

Commit

Permalink
[Auth] Remote httpMethod from AuthRequestConfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
ncooke3 committed Nov 18, 2024
1 parent d84d5ef commit 3b2bb04
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 18 deletions.
10 changes: 5 additions & 5 deletions FirebaseAuth/Sources/Swift/Backend/AuthBackend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,23 @@ final class AuthBackend: AuthBackendProtocol {
}
}

static func request(withURL url: URL,
contentType: String,
requestConfiguration: AuthRequestConfiguration) async -> URLRequest {
static func urlRequest(from rpcRequest: any AuthRPCRequest,
contentType: String,
requestConfiguration: AuthRequestConfiguration) async -> URLRequest {
// Kick off tasks for the async header values.
async let heartbeatsHeaderValue = requestConfiguration.heartbeatLogger?.asyncHeaderValue()
async let appCheckTokenHeaderValue = requestConfiguration.appCheck?
.getToken(forcingRefresh: true)

var request = URLRequest(url: url)
var request = URLRequest(url: rpcRequest.requestURL())
request.setValue(contentType, forHTTPHeaderField: "Content-Type")
let additionalFrameworkMarker = requestConfiguration
.additionalFrameworkMarker ?? "FirebaseCore-iOS"
let clientVersion = "iOS/FirebaseSDK/\(FirebaseVersion())/\(additionalFrameworkMarker)"
request.setValue(clientVersion, forHTTPHeaderField: "X-Client-Version")
request.setValue(Bundle.main.bundleIdentifier, forHTTPHeaderField: "X-Ios-Bundle-Identifier")
request.setValue(requestConfiguration.appID, forHTTPHeaderField: "X-Firebase-GMPID")
request.httpMethod = requestConfiguration.httpMethod
request.httpMethod = rpcRequest.containsPostBody ? "POST" : "GET"
let preferredLocalizations = Bundle.main.preferredLocalizations
if preferredLocalizations.count > 0 {
request.setValue(preferredLocalizations.first, forHTTPHeaderField: "Accept-Language")
Expand Down
8 changes: 5 additions & 3 deletions FirebaseAuth/Sources/Swift/Backend/AuthBackendRPCIssuer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ final class AuthBackendRPCIssuer: AuthBackendRPCIssuerProtocol {
body: Data?,
contentType: String) async -> (Data?, Error?) {
let requestConfiguration = request.requestConfiguration()
let request = await AuthBackend.request(withURL: request.requestURL(),
contentType: contentType,
requestConfiguration: requestConfiguration)
let request = await AuthBackend.urlRequest(
from: request,
contentType: contentType,
requestConfiguration: requestConfiguration
)
let fetcher = fetcherService.fetcher(with: request)
if let _ = requestConfiguration.emulatorHostAndPort {
fetcher.allowLocalhostRequest = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ class AuthRequestConfiguration {
/// The appCheck is used to generate a token.
var appCheck: AppCheckInterop?

/// The HTTP method used in the request.
var httpMethod: String

/// Additional framework marker that will be added as part of the header of every request.
var additionalFrameworkMarker: String?

Expand All @@ -57,6 +54,5 @@ class AuthRequestConfiguration {
self.auth = auth
self.heartbeatLogger = heartbeatLogger
self.appCheck = appCheck
httpMethod = "POST"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@
import Foundation

/// The "getProjectConfig" endpoint.

private let kGetProjectConfigEndPoint = "getProjectConfig"

@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
class GetProjectConfigRequest: IdentityToolkitRequest, AuthRPCRequest {
typealias Response = GetProjectConfigResponse

init(requestConfiguration: AuthRequestConfiguration) {
requestConfiguration.httpMethod = "GET"
super.init(endpoint: kGetProjectConfigEndPoint, requestConfiguration: requestConfiguration)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class GetRecaptchaConfigRequest: IdentityToolkitRequest, AuthRPCRequest {
typealias Response = GetRecaptchaConfigResponse

required init(requestConfiguration: AuthRequestConfiguration) {
requestConfiguration.httpMethod = "GET"
super.init(
endpoint: kGetRecaptchaConfigEndpoint,
requestConfiguration: requestConfiguration,
Expand Down
9 changes: 6 additions & 3 deletions FirebaseAuth/Tests/Unit/Fakes/FakeBackendRPCIssuer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,12 @@ final class FakeBackendRPCIssuer: AuthBackendRPCIssuerProtocol, @unchecked Senda
// Use the real implementation so that the complete request can
// be verified during testing.
completeRequest = Task {
await AuthBackend.request(withURL: requestURL!,
contentType: contentType,
requestConfiguration: request.requestConfiguration())
await AuthBackend
.urlRequest(
from: request,
contentType: contentType,
requestConfiguration: request.requestConfiguration()
)
}
decodedRequest = try? JSONSerialization.jsonObject(with: body) as? [String: Any]
}
Expand Down

0 comments on commit 3b2bb04

Please sign in to comment.