diff --git a/FirebaseAuth/Sources/Swift/Backend/AuthBackend.swift b/FirebaseAuth/Sources/Swift/Backend/AuthBackend.swift index 474f665147f..4a6da4596e5 100644 --- a/FirebaseAuth/Sources/Swift/Backend/AuthBackend.swift +++ b/FirebaseAuth/Sources/Swift/Backend/AuthBackend.swift @@ -60,15 +60,15 @@ 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" @@ -76,7 +76,7 @@ final class AuthBackend: AuthBackendProtocol { 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") diff --git a/FirebaseAuth/Sources/Swift/Backend/AuthBackendRPCIssuer.swift b/FirebaseAuth/Sources/Swift/Backend/AuthBackendRPCIssuer.swift index 6d2c540ff37..dc39252170d 100644 --- a/FirebaseAuth/Sources/Swift/Backend/AuthBackendRPCIssuer.swift +++ b/FirebaseAuth/Sources/Swift/Backend/AuthBackendRPCIssuer.swift @@ -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 diff --git a/FirebaseAuth/Sources/Swift/Backend/AuthRequestConfiguration.swift b/FirebaseAuth/Sources/Swift/Backend/AuthRequestConfiguration.swift index 47aff1be47e..510e9287ca0 100644 --- a/FirebaseAuth/Sources/Swift/Backend/AuthRequestConfiguration.swift +++ b/FirebaseAuth/Sources/Swift/Backend/AuthRequestConfiguration.swift @@ -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? @@ -57,6 +54,5 @@ class AuthRequestConfiguration { self.auth = auth self.heartbeatLogger = heartbeatLogger self.appCheck = appCheck - httpMethod = "POST" } } diff --git a/FirebaseAuth/Sources/Swift/Backend/RPC/GetProjectConfigRequest.swift b/FirebaseAuth/Sources/Swift/Backend/RPC/GetProjectConfigRequest.swift index 1b8f714b60e..b7cb98d7285 100644 --- a/FirebaseAuth/Sources/Swift/Backend/RPC/GetProjectConfigRequest.swift +++ b/FirebaseAuth/Sources/Swift/Backend/RPC/GetProjectConfigRequest.swift @@ -15,7 +15,6 @@ import Foundation /// The "getProjectConfig" endpoint. - private let kGetProjectConfigEndPoint = "getProjectConfig" @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *) @@ -23,7 +22,6 @@ class GetProjectConfigRequest: IdentityToolkitRequest, AuthRPCRequest { typealias Response = GetProjectConfigResponse init(requestConfiguration: AuthRequestConfiguration) { - requestConfiguration.httpMethod = "GET" super.init(endpoint: kGetProjectConfigEndPoint, requestConfiguration: requestConfiguration) } diff --git a/FirebaseAuth/Sources/Swift/Backend/RPC/GetRecaptchaConfigRequest.swift b/FirebaseAuth/Sources/Swift/Backend/RPC/GetRecaptchaConfigRequest.swift index fc8e287a52f..ce3a6ff9b5b 100644 --- a/FirebaseAuth/Sources/Swift/Backend/RPC/GetRecaptchaConfigRequest.swift +++ b/FirebaseAuth/Sources/Swift/Backend/RPC/GetRecaptchaConfigRequest.swift @@ -48,7 +48,6 @@ class GetRecaptchaConfigRequest: IdentityToolkitRequest, AuthRPCRequest { typealias Response = GetRecaptchaConfigResponse required init(requestConfiguration: AuthRequestConfiguration) { - requestConfiguration.httpMethod = "GET" super.init( endpoint: kGetRecaptchaConfigEndpoint, requestConfiguration: requestConfiguration, diff --git a/FirebaseAuth/Tests/Unit/Fakes/FakeBackendRPCIssuer.swift b/FirebaseAuth/Tests/Unit/Fakes/FakeBackendRPCIssuer.swift index 3a40aac37d7..505770f3f6a 100644 --- a/FirebaseAuth/Tests/Unit/Fakes/FakeBackendRPCIssuer.swift +++ b/FirebaseAuth/Tests/Unit/Fakes/FakeBackendRPCIssuer.swift @@ -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] }