From 8df97246b571d8a9c1ec6ef84c2c197a3602438a Mon Sep 17 00:00:00 2001 From: Nick Cooke Date: Wed, 30 Oct 2024 16:09:13 -0400 Subject: [PATCH 01/13] [Auth] Update SecureTokenRequest to have only immutable properties --- .../Swift/Backend/RPC/SecureTokenRequest.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/FirebaseAuth/Sources/Swift/Backend/RPC/SecureTokenRequest.swift b/FirebaseAuth/Sources/Swift/Backend/RPC/SecureTokenRequest.swift index 920afc34158..e7fa5ee57e5 100644 --- a/FirebaseAuth/Sources/Swift/Backend/RPC/SecureTokenRequest.swift +++ b/FirebaseAuth/Sources/Swift/Backend/RPC/SecureTokenRequest.swift @@ -64,16 +64,16 @@ class SecureTokenRequest: AuthRPCRequest { /// The type of grant requested. /// See FIRSecureTokenRequestGrantType - var grantType: SecureTokenRequestGrantType + let grantType: SecureTokenRequestGrantType /// The scopes requested (a comma-delimited list of scope strings). - var scope: String? + let scope: String? /// The client's refresh token. - var refreshToken: String? + let refreshToken: String? /// The client's authorization code (legacy Gitkit "ID Token"). - var code: String? + let code: String? /// The client's API Key. let apiKey: String @@ -107,8 +107,8 @@ class SecureTokenRequest: AuthRPCRequest { ) } - init(grantType: SecureTokenRequestGrantType, scope: String?, refreshToken: String?, - code: String?, requestConfiguration: AuthRequestConfiguration) { + private init(grantType: SecureTokenRequestGrantType, scope: String?, refreshToken: String?, + code: String?, requestConfiguration: AuthRequestConfiguration) { self.grantType = grantType self.scope = scope self.refreshToken = refreshToken From ac67174052bbdc492d903c72709b1d246d3d311d Mon Sep 17 00:00:00 2001 From: Nick Cooke Date: Wed, 30 Oct 2024 16:12:25 -0400 Subject: [PATCH 02/13] [Auth] Update WithdrawMFARequest to have only immutable properties --- .../Backend/RPC/MultiFactor/Unenroll/WithdrawMFARequest.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FirebaseAuth/Sources/Swift/Backend/RPC/MultiFactor/Unenroll/WithdrawMFARequest.swift b/FirebaseAuth/Sources/Swift/Backend/RPC/MultiFactor/Unenroll/WithdrawMFARequest.swift index 5f8156a5191..19d9a04faed 100644 --- a/FirebaseAuth/Sources/Swift/Backend/RPC/MultiFactor/Unenroll/WithdrawMFARequest.swift +++ b/FirebaseAuth/Sources/Swift/Backend/RPC/MultiFactor/Unenroll/WithdrawMFARequest.swift @@ -23,8 +23,8 @@ private let kTenantIDKey = "tenantId" class WithdrawMFARequest: IdentityToolkitRequest, AuthRPCRequest { typealias Response = WithdrawMFAResponse - var idToken: String? - var mfaEnrollmentID: String? + let idToken: String? + let mfaEnrollmentID: String? init(idToken: String?, mfaEnrollmentID: String?, From 5d465b0bb94a59ae1f8c60a2d6206f2660acb98a Mon Sep 17 00:00:00 2001 From: Nick Cooke Date: Wed, 30 Oct 2024 16:13:32 -0400 Subject: [PATCH 03/13] [Auth] Update StartMFASignInRequest to have only immutable properties --- .../RPC/MultiFactor/SignIn/StartMFASignInRequest.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/FirebaseAuth/Sources/Swift/Backend/RPC/MultiFactor/SignIn/StartMFASignInRequest.swift b/FirebaseAuth/Sources/Swift/Backend/RPC/MultiFactor/SignIn/StartMFASignInRequest.swift index 413245776a7..1098c2ef4ea 100644 --- a/FirebaseAuth/Sources/Swift/Backend/RPC/MultiFactor/SignIn/StartMFASignInRequest.swift +++ b/FirebaseAuth/Sources/Swift/Backend/RPC/MultiFactor/SignIn/StartMFASignInRequest.swift @@ -24,9 +24,9 @@ private let kTenantIDKey = "tenantId" class StartMFASignInRequest: IdentityToolkitRequest, AuthRPCRequest { typealias Response = StartMFASignInResponse - var MFAPendingCredential: String? - var MFAEnrollmentID: String? - var signInInfo: AuthProtoStartMFAPhoneRequestInfo? + let MFAPendingCredential: String? + let MFAEnrollmentID: String? + let signInInfo: AuthProtoStartMFAPhoneRequestInfo? init(MFAPendingCredential: String?, MFAEnrollmentID: String?, signInInfo: AuthProtoStartMFAPhoneRequestInfo?, From 8ceae78bd7bcc3d9d54000fc646fc9256297d655 Mon Sep 17 00:00:00 2001 From: Nick Cooke Date: Wed, 30 Oct 2024 16:14:08 -0400 Subject: [PATCH 04/13] [Auth] Update FinalizeMFASignInRequest to have only immutable properties --- .../RPC/MultiFactor/SignIn/FinalizeMFASignInRequest.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FirebaseAuth/Sources/Swift/Backend/RPC/MultiFactor/SignIn/FinalizeMFASignInRequest.swift b/FirebaseAuth/Sources/Swift/Backend/RPC/MultiFactor/SignIn/FinalizeMFASignInRequest.swift index 53f8a783b67..399e426d456 100644 --- a/FirebaseAuth/Sources/Swift/Backend/RPC/MultiFactor/SignIn/FinalizeMFASignInRequest.swift +++ b/FirebaseAuth/Sources/Swift/Backend/RPC/MultiFactor/SignIn/FinalizeMFASignInRequest.swift @@ -23,8 +23,8 @@ private let kTenantIDKey = "tenantId" class FinalizeMFASignInRequest: IdentityToolkitRequest, AuthRPCRequest { typealias Response = FinalizeMFAEnrollmentResponse - var mfaPendingCredential: String? - var verificationInfo: AuthProto? + let mfaPendingCredential: String? + let verificationInfo: AuthProto? init(mfaPendingCredential: String?, verificationInfo: AuthProto?, From 233b3c7ffc0a6e68e1486a1a77cd964793e5309e Mon Sep 17 00:00:00 2001 From: Nick Cooke Date: Wed, 30 Oct 2024 16:21:42 -0400 Subject: [PATCH 05/13] [Auth] Update StartMFAEnrollmentRequest to have only immutable properties --- .../Enroll/StartMFAEnrollmentRequest.swift | 43 ++++++++++++------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/FirebaseAuth/Sources/Swift/Backend/RPC/MultiFactor/Enroll/StartMFAEnrollmentRequest.swift b/FirebaseAuth/Sources/Swift/Backend/RPC/MultiFactor/Enroll/StartMFAEnrollmentRequest.swift index 2ae904eac46..3896ec14b3d 100644 --- a/FirebaseAuth/Sources/Swift/Backend/RPC/MultiFactor/Enroll/StartMFAEnrollmentRequest.swift +++ b/FirebaseAuth/Sources/Swift/Backend/RPC/MultiFactor/Enroll/StartMFAEnrollmentRequest.swift @@ -24,30 +24,43 @@ class StartMFAEnrollmentRequest: IdentityToolkitRequest, AuthRPCRequest { typealias Response = StartMFAEnrollmentResponse let idToken: String? - private(set) var phoneEnrollmentInfo: AuthProtoStartMFAPhoneRequestInfo? - private(set) var totpEnrollmentInfo: AuthProtoStartMFATOTPEnrollmentRequestInfo? + let phoneEnrollmentInfo: AuthProtoStartMFAPhoneRequestInfo? + let totpEnrollmentInfo: AuthProtoStartMFATOTPEnrollmentRequestInfo? - init(idToken: String?, - enrollmentInfo: AuthProtoStartMFAPhoneRequestInfo?, - requestConfiguration: AuthRequestConfiguration) { - self.idToken = idToken - phoneEnrollmentInfo = enrollmentInfo - super.init( - endpoint: kStartMFAEnrollmentEndPoint, - requestConfiguration: requestConfiguration, - useIdentityPlatform: true + convenience init(idToken: String?, + enrollmentInfo: AuthProtoStartMFAPhoneRequestInfo?, + requestConfiguration: AuthRequestConfiguration) { + self.init( + idToken: idToken, + enrollmentInfo: enrollmentInfo, + totpEnrollmentInfo: nil, + requestConfiguration: requestConfiguration ) } - init(idToken: String?, - totpEnrollmentInfo: AuthProtoStartMFATOTPEnrollmentRequestInfo?, - requestConfiguration: AuthRequestConfiguration) { + convenience init(idToken: String?, + totpEnrollmentInfo: AuthProtoStartMFATOTPEnrollmentRequestInfo?, + requestConfiguration: AuthRequestConfiguration) { + self.init( + idToken: idToken, + enrollmentInfo: nil, + totpEnrollmentInfo: totpEnrollmentInfo, + requestConfiguration: requestConfiguration + ) + } + + private init(idToken: String?, + enrollmentInfo: AuthProtoStartMFAPhoneRequestInfo?, + totpEnrollmentInfo: AuthProtoStartMFATOTPEnrollmentRequestInfo?, + requestConfiguration: AuthRequestConfiguration) { self.idToken = idToken + phoneEnrollmentInfo = enrollmentInfo self.totpEnrollmentInfo = totpEnrollmentInfo super.init( endpoint: kStartMFAEnrollmentEndPoint, requestConfiguration: requestConfiguration, - useIdentityPlatform: true + useIdentityPlatform: true, + useStaging: false ) } From c920a6a0303f4afcc1ef2e4b29b4c2297a9f6783 Mon Sep 17 00:00:00 2001 From: Nick Cooke Date: Wed, 30 Oct 2024 16:31:01 -0400 Subject: [PATCH 06/13] [Auth] Update FinalizeMFAEnrollmentRequest to have only immutable properties --- .../Enroll/FinalizeMFAEnrollmentRequest.swift | 46 ++++++++++++------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/FirebaseAuth/Sources/Swift/Backend/RPC/MultiFactor/Enroll/FinalizeMFAEnrollmentRequest.swift b/FirebaseAuth/Sources/Swift/Backend/RPC/MultiFactor/Enroll/FinalizeMFAEnrollmentRequest.swift index e7c478e23bd..89374c9de4f 100644 --- a/FirebaseAuth/Sources/Swift/Backend/RPC/MultiFactor/Enroll/FinalizeMFAEnrollmentRequest.swift +++ b/FirebaseAuth/Sources/Swift/Backend/RPC/MultiFactor/Enroll/FinalizeMFAEnrollmentRequest.swift @@ -27,33 +27,47 @@ class FinalizeMFAEnrollmentRequest: IdentityToolkitRequest, AuthRPCRequest { let displayName: String? - var phoneVerificationInfo: AuthProtoFinalizeMFAPhoneRequestInfo? + let phoneVerificationInfo: AuthProtoFinalizeMFAPhoneRequestInfo? - var totpVerificationInfo: AuthProtoFinalizeMFATOTPEnrollmentRequestInfo? + let totpVerificationInfo: AuthProtoFinalizeMFATOTPEnrollmentRequestInfo? - init(idToken: String?, displayName: String?, - phoneVerificationInfo: AuthProtoFinalizeMFAPhoneRequestInfo?, - requestConfiguration: AuthRequestConfiguration) { - self.idToken = idToken - self.displayName = displayName - self.phoneVerificationInfo = phoneVerificationInfo - super.init( - endpoint: kFinalizeMFAEnrollmentEndPoint, - requestConfiguration: requestConfiguration, - useIdentityPlatform: true + convenience init(idToken: String?, displayName: String?, + phoneVerificationInfo: AuthProtoFinalizeMFAPhoneRequestInfo?, + requestConfiguration: AuthRequestConfiguration) { + self.init( + idToken: idToken, + displayName: displayName, + phoneVerificationInfo: phoneVerificationInfo, + totpVerificationInfo: nil, + requestConfiguration: requestConfiguration ) } - init(idToken: String?, displayName: String?, - totpVerificationInfo: AuthProtoFinalizeMFATOTPEnrollmentRequestInfo?, - requestConfiguration: AuthRequestConfiguration) { + convenience init(idToken: String?, displayName: String?, + totpVerificationInfo: AuthProtoFinalizeMFATOTPEnrollmentRequestInfo?, + requestConfiguration: AuthRequestConfiguration) { + self.init( + idToken: idToken, + displayName: displayName, + phoneVerificationInfo: nil, + totpVerificationInfo: totpVerificationInfo, + requestConfiguration: requestConfiguration + ) + } + + private init(idToken: String?, displayName: String?, + phoneVerificationInfo: AuthProtoFinalizeMFAPhoneRequestInfo?, + totpVerificationInfo: AuthProtoFinalizeMFATOTPEnrollmentRequestInfo?, + requestConfiguration: AuthRequestConfiguration) { self.idToken = idToken self.displayName = displayName + self.phoneVerificationInfo = phoneVerificationInfo self.totpVerificationInfo = totpVerificationInfo super.init( endpoint: kFinalizeMFAEnrollmentEndPoint, requestConfiguration: requestConfiguration, - useIdentityPlatform: true + useIdentityPlatform: true, + useStaging: false ) } From 7ded4e2b7da2101228506824fe8317de52c6da19 Mon Sep 17 00:00:00 2001 From: Nick Cooke Date: Wed, 30 Oct 2024 16:43:30 -0400 Subject: [PATCH 07/13] [Auth] Update VerifyPhoneNumberRequest to have only immutable properties --- .../RPC/VerifyPhoneNumberRequest.swift | 60 +++++++++++++------ 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/FirebaseAuth/Sources/Swift/Backend/RPC/VerifyPhoneNumberRequest.swift b/FirebaseAuth/Sources/Swift/Backend/RPC/VerifyPhoneNumberRequest.swift index 2fb0b183709..791c6fc9e01 100644 --- a/FirebaseAuth/Sources/Swift/Backend/RPC/VerifyPhoneNumberRequest.swift +++ b/FirebaseAuth/Sources/Swift/Backend/RPC/VerifyPhoneNumberRequest.swift @@ -61,52 +61,76 @@ class VerifyPhoneNumberRequest: IdentityToolkitRequest, AuthRPCRequest { typealias Response = VerifyPhoneNumberResponse /// The verification ID obtained from the response of `sendVerificationCode`. - var verificationID: String? + let verificationID: String? /// The verification code provided by the user. - var verificationCode: String? + let verificationCode: String? /// The STS Access Token for the authenticated user. var accessToken: String? /// The temporary proof code, previously returned from the backend. - var temporaryProof: String? + let temporaryProof: String? /// The phone number to be verified in the request. - var phoneNumber: String? + let phoneNumber: String? /// The type of operation triggering this verify phone number request. - var operation: AuthOperationType + let operation: AuthOperationType - /// Designated initializer. + /// Convenience initializer. /// - Parameter temporaryProof: The temporary proof sent by the backed. /// - Parameter phoneNumber: The phone number associated with the credential to be signed in . /// - Parameter operation: Indicates what operation triggered the verify phone number request. /// - Parameter requestConfiguration: An object containing configurations to be added to the /// request. - init(temporaryProof: String, phoneNumber: String, operation: AuthOperationType, - requestConfiguration: AuthRequestConfiguration) { - self.temporaryProof = temporaryProof - self.phoneNumber = phoneNumber - self.operation = operation - super.init(endpoint: kVerifyPhoneNumberEndPoint, requestConfiguration: requestConfiguration) + convenience init(temporaryProof: String, phoneNumber: String, operation: AuthOperationType, + requestConfiguration: AuthRequestConfiguration) { + self.init( + temporaryProof: temporaryProof, + phoneNumber: phoneNumber, + verificationID: nil, + verificationCode: nil, + operation: operation, + requestConfiguration: requestConfiguration + ) } - /// Designated initializer. + /// Convenience initializer. /// - Parameter verificationID: The verification ID obtained from the response of /// `sendVerificationCode`. /// - Parameter verificationCode: The verification code provided by the user. /// - Parameter operation: Indicates what operation triggered the verify phone number request. /// - Parameter requestConfiguration: An object containing configurations to be added to the /// request. - init(verificationID: String, - verificationCode: String, - operation: AuthOperationType, - requestConfiguration: AuthRequestConfiguration) { + convenience init(verificationID: String, + verificationCode: String, + operation: AuthOperationType, + requestConfiguration: AuthRequestConfiguration) { + self.init( + temporaryProof: nil, + phoneNumber: nil, + verificationID: verificationID, + verificationCode: verificationCode, + operation: operation, + requestConfiguration: requestConfiguration + ) + } + + private init(temporaryProof: String?, phoneNumber: String?, verificationID: String?, + verificationCode: String?, operation: AuthOperationType, + requestConfiguration: AuthRequestConfiguration) { + self.temporaryProof = temporaryProof + self.phoneNumber = phoneNumber self.verificationID = verificationID self.verificationCode = verificationCode self.operation = operation - super.init(endpoint: kVerifyPhoneNumberEndPoint, requestConfiguration: requestConfiguration) + super.init( + endpoint: kVerifyPhoneNumberEndPoint, + requestConfiguration: requestConfiguration, + useIdentityPlatform: false, + useStaging: false + ) } func unencodedHTTPRequestBody() throws -> [String: AnyHashable] { From ba922b257c1932c1326a8fbc9a515a0dff9d6755 Mon Sep 17 00:00:00 2001 From: Nick Cooke Date: Wed, 30 Oct 2024 16:48:06 -0400 Subject: [PATCH 08/13] [Auth] Update VerifyClientRequest to have only immutable properties --- FirebaseAuth/Sources/Swift/Backend/VerifyClientRequest.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FirebaseAuth/Sources/Swift/Backend/VerifyClientRequest.swift b/FirebaseAuth/Sources/Swift/Backend/VerifyClientRequest.swift index 892e0cbd4c1..f62f9def230 100644 --- a/FirebaseAuth/Sources/Swift/Backend/VerifyClientRequest.swift +++ b/FirebaseAuth/Sources/Swift/Backend/VerifyClientRequest.swift @@ -39,10 +39,10 @@ class VerifyClientRequest: IdentityToolkitRequest, AuthRPCRequest { } /// The APNS device token. - private(set) var appToken: String? + let appToken: String? /// The flag that denotes if the appToken pertains to Sandbox or Production. - private(set) var isSandbox: Bool + let isSandbox: Bool init(withAppToken appToken: String?, isSandbox: Bool, From b9db78b587321db60e9c775aadd8fa331deb3e63 Mon Sep 17 00:00:00 2001 From: Nick Cooke Date: Wed, 30 Oct 2024 16:51:16 -0400 Subject: [PATCH 09/13] [Auth] Update CreateAuthURIRequest to have only immutable properties --- .../Swift/Backend/RPC/CreateAuthURIRequest.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/FirebaseAuth/Sources/Swift/Backend/RPC/CreateAuthURIRequest.swift b/FirebaseAuth/Sources/Swift/Backend/RPC/CreateAuthURIRequest.swift index 1a7503ced9a..9f70aa7693a 100644 --- a/FirebaseAuth/Sources/Swift/Backend/RPC/CreateAuthURIRequest.swift +++ b/FirebaseAuth/Sources/Swift/Backend/RPC/CreateAuthURIRequest.swift @@ -48,28 +48,28 @@ class CreateAuthURIRequest: IdentityToolkitRequest, AuthRPCRequest { typealias Response = CreateAuthURIResponse /// The email or federated ID of the user. - let identifier: String + private let identifier: String /// The URI to which the IDP redirects the user after the federated login flow. - let continueURI: String + private let continueURI: String /// Optional realm for OpenID protocol. The sub string "scheme://domain:port" of the param /// "continueUri" is used if this is not set. - var openIDRealm: String? + private let openIDRealm: String? = nil /// The IdP ID. For white listed IdPs it's a short domain name e.g. google.com, aol.com, /// live.net and yahoo.com. For other OpenID IdPs it's the OP identifier. - var providerID: String? + private let providerID: String? = nil /// The relying party OAuth client ID. - var clientID: String? + private let clientID: String? = nil /// The opaque value used by the client to maintain context info between the authentication /// request and the IDP callback. - var context: String? + private let context: String? = nil /// The iOS client application's bundle identifier. - var appID: String? + private let appID: String? = nil init(identifier: String, continueURI: String, requestConfiguration: AuthRequestConfiguration) { From 70901ae8859062ceb820f4a8819ed38a7c025b0d Mon Sep 17 00:00:00 2001 From: Nick Cooke Date: Wed, 30 Oct 2024 16:55:21 -0400 Subject: [PATCH 10/13] [Auth] Update GetOOBConfirmationCodeRequest to have only immutable properties --- .../RPC/GetOOBConfirmationCodeRequest.swift | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/FirebaseAuth/Sources/Swift/Backend/RPC/GetOOBConfirmationCodeRequest.swift b/FirebaseAuth/Sources/Swift/Backend/RPC/GetOOBConfirmationCodeRequest.swift index 7c1fc262c0b..06f03373c28 100644 --- a/FirebaseAuth/Sources/Swift/Backend/RPC/GetOOBConfirmationCodeRequest.swift +++ b/FirebaseAuth/Sources/Swift/Backend/RPC/GetOOBConfirmationCodeRequest.swift @@ -107,44 +107,44 @@ class GetOOBConfirmationCodeRequest: IdentityToolkitRequest, AuthRPCRequest { typealias Response = GetOOBConfirmationCodeResponse /// The types of OOB Confirmation Code to request. - let requestType: GetOOBConfirmationCodeRequestType + private let requestType: GetOOBConfirmationCodeRequestType /// The email of the user for password reset. - private(set) var email: String? + private let email: String? /// The new email to be updated for verifyBeforeUpdateEmail. - private(set) var updatedEmail: String? + private let updatedEmail: String? /// The STS Access Token of the authenticated user for email change. - private(set) var accessToken: String? + private let accessToken: String? /// This URL represents the state/Continue URL in the form of a universal link. - private(set) var continueURL: String? + private let continueURL: String? /// The iOS bundle Identifier, if available. - private(set) var iOSBundleID: String? + private let iOSBundleID: String? /// The Android package name, if available. - private(set) var androidPackageName: String? + private let androidPackageName: String? /// The minimum Android version supported, if available. - private(set) var androidMinimumVersion: String? + private let androidMinimumVersion: String? /// Indicates whether or not the Android app should be installed if not already available. - private(set) var androidInstallApp: Bool + private let androidInstallApp: Bool /// Indicates whether the action code link will open the app directly or after being /// redirected from a Firebase owned web widget. - private(set) var handleCodeInApp: Bool + private let handleCodeInApp: Bool /// The Firebase Dynamic Link domain used for out of band code flow. - private(set) var dynamicLinkDomain: String? + private let dynamicLinkDomain: String? /// Response to the captcha. - var captchaResponse: String? + private(set) var captchaResponse: String? /// The reCAPTCHA version. - var recaptchaVersion: String? + private(set) var recaptchaVersion: String? /// Designated initializer. /// - Parameter requestType: The types of OOB Confirmation Code to request. From 054ab16197a9c4ae326a42f8d71831c12c209652 Mon Sep 17 00:00:00 2001 From: Nick Cooke Date: Wed, 30 Oct 2024 16:57:22 -0400 Subject: [PATCH 11/13] [Auth] Update RevokeTokenRequest to have only immutable properties --- .../Sources/Swift/Backend/RPC/RevokeTokenRequest.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/FirebaseAuth/Sources/Swift/Backend/RPC/RevokeTokenRequest.swift b/FirebaseAuth/Sources/Swift/Backend/RPC/RevokeTokenRequest.swift index 632060237dd..8f76aca43a2 100644 --- a/FirebaseAuth/Sources/Swift/Backend/RPC/RevokeTokenRequest.swift +++ b/FirebaseAuth/Sources/Swift/Backend/RPC/RevokeTokenRequest.swift @@ -37,16 +37,16 @@ class RevokeTokenRequest: IdentityToolkitRequest, AuthRPCRequest { typealias Response = RevokeTokenResponse /// The provider that issued the token to revoke. - private(set) var providerID: String + private let providerID: String /// The type of the token to revoke. - private(set) var tokenType: TokenType + private let tokenType: TokenType /// The token to be revoked. - private(set) var token: String + private let token: String /// The ID Token associated with this credential. - private(set) var idToken: String + private let idToken: String enum TokenType: Int { case unspecified = 0, refreshToken = 1, accessToken = 2, authorizationCode = 3 From df79d27e955b0c218464764f820a55f3c2b657d2 Mon Sep 17 00:00:00 2001 From: Nick Cooke Date: Wed, 30 Oct 2024 17:02:50 -0400 Subject: [PATCH 12/13] [Auth] Lock down property visibility for SetAccountInfoRequest --- .../Backend/RPC/SetAccountInfoRequest.swift | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/FirebaseAuth/Sources/Swift/Backend/RPC/SetAccountInfoRequest.swift b/FirebaseAuth/Sources/Swift/Backend/RPC/SetAccountInfoRequest.swift index be61874df7f..ef6a52578f3 100644 --- a/FirebaseAuth/Sources/Swift/Backend/RPC/SetAccountInfoRequest.swift +++ b/FirebaseAuth/Sources/Swift/Backend/RPC/SetAccountInfoRequest.swift @@ -89,47 +89,47 @@ class SetAccountInfoRequest: IdentityToolkitRequest, AuthRPCRequest { var displayName: String? /// The local ID of the user. - var localID: String? + private let localID: String? = nil /// The email of the user. - var email: String? + var email: String? = nil /// The photoURL of the user. var photoURL: URL? /// The new password of the user. - var password: String? + var password: String? = nil /// The associated identity providers of the user. - var providers: [String]? + private let providers: [String]? = nil /// The out-of-band code of the change email request. var oobCode: String? /// Whether to mark the email as verified or not. - var emailVerified: Bool = false + private let emailVerified: Bool = false /// Whether to mark the user to upgrade to federated login. - var upgradeToFederatedLogin: Bool = false + private let upgradeToFederatedLogin: Bool = false /// The captcha challenge. - var captchaChallenge: String? + private let captchaChallenge: String? = nil /// Response to the captcha. - var captchaResponse: String? + private let captchaResponse: String? = nil /// The list of user attributes to delete. /// /// Every element of the list must be one of the predefined constant starts with /// `SetAccountInfoUserAttribute`. - var deleteAttributes: [String]? + private let deleteAttributes: [String]? = nil /// The list of identity providers to delete. var deleteProviders: [String]? /// Whether the response should return access token and refresh token directly. /// The default value is `true` . - var returnSecureToken: Bool = true + private let returnSecureToken: Bool = true init(requestConfiguration: AuthRequestConfiguration) { super.init(endpoint: kSetAccountInfoEndpoint, requestConfiguration: requestConfiguration) From c070fc5de80c54052525ee518172058b96100457 Mon Sep 17 00:00:00 2001 From: Nick Cooke Date: Wed, 30 Oct 2024 17:13:11 -0400 Subject: [PATCH 13/13] Various fixes --- .../Backend/RPC/CreateAuthURIRequest.swift | 2 +- .../RPC/GetOOBConfirmationCodeRequest.swift | 10 +++++----- .../Backend/RPC/RevokeTokenRequest.swift | 6 +++--- .../Backend/RPC/SetAccountInfoRequest.swift | 19 ++++++++++--------- .../Swift/User/UserProfileUpdate.swift | 11 +++++++---- .../Tests/Unit/SetAccountInfoTests.swift | 2 +- 6 files changed, 27 insertions(+), 23 deletions(-) diff --git a/FirebaseAuth/Sources/Swift/Backend/RPC/CreateAuthURIRequest.swift b/FirebaseAuth/Sources/Swift/Backend/RPC/CreateAuthURIRequest.swift index 9f70aa7693a..419419f4862 100644 --- a/FirebaseAuth/Sources/Swift/Backend/RPC/CreateAuthURIRequest.swift +++ b/FirebaseAuth/Sources/Swift/Backend/RPC/CreateAuthURIRequest.swift @@ -48,7 +48,7 @@ class CreateAuthURIRequest: IdentityToolkitRequest, AuthRPCRequest { typealias Response = CreateAuthURIResponse /// The email or federated ID of the user. - private let identifier: String + let identifier: String /// The URI to which the IDP redirects the user after the federated login flow. private let continueURI: String diff --git a/FirebaseAuth/Sources/Swift/Backend/RPC/GetOOBConfirmationCodeRequest.swift b/FirebaseAuth/Sources/Swift/Backend/RPC/GetOOBConfirmationCodeRequest.swift index 06f03373c28..c1de49fd071 100644 --- a/FirebaseAuth/Sources/Swift/Backend/RPC/GetOOBConfirmationCodeRequest.swift +++ b/FirebaseAuth/Sources/Swift/Backend/RPC/GetOOBConfirmationCodeRequest.swift @@ -110,7 +110,7 @@ class GetOOBConfirmationCodeRequest: IdentityToolkitRequest, AuthRPCRequest { private let requestType: GetOOBConfirmationCodeRequestType /// The email of the user for password reset. - private let email: String? + let email: String? /// The new email to be updated for verifyBeforeUpdateEmail. private let updatedEmail: String? @@ -119,7 +119,7 @@ class GetOOBConfirmationCodeRequest: IdentityToolkitRequest, AuthRPCRequest { private let accessToken: String? /// This URL represents the state/Continue URL in the form of a universal link. - private let continueURL: String? + let continueURL: String? /// The iOS bundle Identifier, if available. private let iOSBundleID: String? @@ -135,16 +135,16 @@ class GetOOBConfirmationCodeRequest: IdentityToolkitRequest, AuthRPCRequest { /// Indicates whether the action code link will open the app directly or after being /// redirected from a Firebase owned web widget. - private let handleCodeInApp: Bool + let handleCodeInApp: Bool /// The Firebase Dynamic Link domain used for out of band code flow. private let dynamicLinkDomain: String? /// Response to the captcha. - private(set) var captchaResponse: String? + var captchaResponse: String? /// The reCAPTCHA version. - private(set) var recaptchaVersion: String? + var recaptchaVersion: String? /// Designated initializer. /// - Parameter requestType: The types of OOB Confirmation Code to request. diff --git a/FirebaseAuth/Sources/Swift/Backend/RPC/RevokeTokenRequest.swift b/FirebaseAuth/Sources/Swift/Backend/RPC/RevokeTokenRequest.swift index 8f76aca43a2..c3afae3b573 100644 --- a/FirebaseAuth/Sources/Swift/Backend/RPC/RevokeTokenRequest.swift +++ b/FirebaseAuth/Sources/Swift/Backend/RPC/RevokeTokenRequest.swift @@ -37,13 +37,13 @@ class RevokeTokenRequest: IdentityToolkitRequest, AuthRPCRequest { typealias Response = RevokeTokenResponse /// The provider that issued the token to revoke. - private let providerID: String + let providerID: String /// The type of the token to revoke. - private let tokenType: TokenType + let tokenType: TokenType /// The token to be revoked. - private let token: String + let token: String /// The ID Token associated with this credential. private let idToken: String diff --git a/FirebaseAuth/Sources/Swift/Backend/RPC/SetAccountInfoRequest.swift b/FirebaseAuth/Sources/Swift/Backend/RPC/SetAccountInfoRequest.swift index ef6a52578f3..82842ace520 100644 --- a/FirebaseAuth/Sources/Swift/Backend/RPC/SetAccountInfoRequest.swift +++ b/FirebaseAuth/Sources/Swift/Backend/RPC/SetAccountInfoRequest.swift @@ -89,7 +89,7 @@ class SetAccountInfoRequest: IdentityToolkitRequest, AuthRPCRequest { var displayName: String? /// The local ID of the user. - private let localID: String? = nil + var localID: String? = nil /// The email of the user. var email: String? = nil @@ -101,37 +101,38 @@ class SetAccountInfoRequest: IdentityToolkitRequest, AuthRPCRequest { var password: String? = nil /// The associated identity providers of the user. - private let providers: [String]? = nil + var providers: [String]? = nil /// The out-of-band code of the change email request. var oobCode: String? /// Whether to mark the email as verified or not. - private let emailVerified: Bool = false + var emailVerified: Bool = false /// Whether to mark the user to upgrade to federated login. - private let upgradeToFederatedLogin: Bool = false + var upgradeToFederatedLogin: Bool = false /// The captcha challenge. - private let captchaChallenge: String? = nil + var captchaChallenge: String? = nil /// Response to the captcha. - private let captchaResponse: String? = nil + var captchaResponse: String? = nil /// The list of user attributes to delete. /// /// Every element of the list must be one of the predefined constant starts with /// `SetAccountInfoUserAttribute`. - private let deleteAttributes: [String]? = nil + var deleteAttributes: [String]? = nil /// The list of identity providers to delete. var deleteProviders: [String]? /// Whether the response should return access token and refresh token directly. /// The default value is `true` . - private let returnSecureToken: Bool = true + var returnSecureToken: Bool = true - init(requestConfiguration: AuthRequestConfiguration) { + init(accessToken: String? = nil, requestConfiguration: AuthRequestConfiguration) { + self.accessToken = accessToken super.init(endpoint: kSetAccountInfoEndpoint, requestConfiguration: requestConfiguration) } diff --git a/FirebaseAuth/Sources/Swift/User/UserProfileUpdate.swift b/FirebaseAuth/Sources/Swift/User/UserProfileUpdate.swift index 75ff6a9168c..2d561246557 100644 --- a/FirebaseAuth/Sources/Swift/User/UserProfileUpdate.swift +++ b/FirebaseAuth/Sources/Swift/User/UserProfileUpdate.swift @@ -49,8 +49,9 @@ actor UserProfileUpdate { func unlink(user: User, fromProvider provider: String) async throws -> User { let accessToken = try await user.internalGetTokenAsync() - let request = SetAccountInfoRequest(requestConfiguration: user.requestConfiguration) - request.accessToken = accessToken + let request = SetAccountInfoRequest( + accessToken: accessToken, requestConfiguration: user.requestConfiguration + ) if user.providerDataRaw[provider] == nil { throw AuthErrorUtils.noSuchProviderError() @@ -108,8 +109,10 @@ actor UserProfileUpdate { // Mutate setAccountInfoRequest in block let setAccountInfoRequest = - SetAccountInfoRequest(requestConfiguration: user.requestConfiguration) - setAccountInfoRequest.accessToken = accessToken + SetAccountInfoRequest( + accessToken: accessToken, + requestConfiguration: user.requestConfiguration + ) changeBlock(userAccountInfo, setAccountInfoRequest) do { let accountInfoResponse = try await AuthBackend.call(with: setAccountInfoRequest) diff --git a/FirebaseAuth/Tests/Unit/SetAccountInfoTests.swift b/FirebaseAuth/Tests/Unit/SetAccountInfoTests.swift index 061b23e3707..4efe951991a 100644 --- a/FirebaseAuth/Tests/Unit/SetAccountInfoTests.swift +++ b/FirebaseAuth/Tests/Unit/SetAccountInfoTests.swift @@ -221,6 +221,6 @@ class SetAccountInfoTests: RPCBaseTests { } private func setAccountInfoRequest() -> SetAccountInfoRequest { - return SetAccountInfoRequest(requestConfiguration: makeRequestConfiguration()) + return SetAccountInfoRequest(accessToken: nil, requestConfiguration: makeRequestConfiguration()) } }