diff --git a/FirebaseAuth/CHANGELOG.md b/FirebaseAuth/CHANGELOG.md index fd141940888..9a878b35ca7 100644 --- a/FirebaseAuth/CHANGELOG.md +++ b/FirebaseAuth/CHANGELOG.md @@ -1,3 +1,7 @@ +# Unreleased +- [fixed] Updated most decoders to be consistent with Firebase 10's behavior + for decoding `nil` values. (#14212) + # 11.6.0 - [added] Added reCAPTCHA Enterprise support for app verification during phone authentication for Firebase Authentication (#14114) diff --git a/FirebaseAuth/Sources/Swift/AuthProvider/FacebookAuthProvider.swift b/FirebaseAuth/Sources/Swift/AuthProvider/FacebookAuthProvider.swift index 59cb2385425..b02ee16854d 100644 --- a/FirebaseAuth/Sources/Swift/AuthProvider/FacebookAuthProvider.swift +++ b/FirebaseAuth/Sources/Swift/AuthProvider/FacebookAuthProvider.swift @@ -36,7 +36,7 @@ import Foundation @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *) @objc(FIRFacebookAuthCredential) class FacebookAuthCredential: AuthCredential, NSSecureCoding, @unchecked Sendable { - let accessToken: String + let accessToken: String? init(withAccessToken accessToken: String) { self.accessToken = accessToken @@ -56,11 +56,7 @@ import Foundation } required init?(coder: NSCoder) { - guard let accessToken = coder.decodeObject(of: NSString.self, forKey: "accessToken") as? String - else { - return nil - } - self.accessToken = accessToken + accessToken = coder.decodeObject(of: NSString.self, forKey: "accessToken") as String? super.init(provider: FacebookAuthProvider.id) } } diff --git a/FirebaseAuth/Sources/Swift/AuthProvider/GameCenterAuthProvider.swift b/FirebaseAuth/Sources/Swift/AuthProvider/GameCenterAuthProvider.swift index 82836ee81b0..935418f27d5 100644 --- a/FirebaseAuth/Sources/Swift/AuthProvider/GameCenterAuthProvider.swift +++ b/FirebaseAuth/Sources/Swift/AuthProvider/GameCenterAuthProvider.swift @@ -130,14 +130,14 @@ @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *) @objc(FIRGameCenterAuthCredential) class GameCenterAuthCredential: AuthCredential, NSSecureCoding, @unchecked Sendable { - let playerID: String + let playerID: String? let teamPlayerID: String? let gamePlayerID: String? let publicKeyURL: URL? let signature: Data? let salt: Data? - let timestamp: UInt64 - let displayName: String + let timestamp: UInt64? + let displayName: String? /// - Parameter playerID: The ID of the Game Center local player. /// - Parameter teamPlayerID: The teamPlayerID of the Game Center local player. @@ -177,27 +177,20 @@ } required init?(coder: NSCoder) { - guard let playerID = coder.decodeObject(of: NSString.self, forKey: "playerID") as? String, - let teamPlayerID = coder.decodeObject( - of: NSString.self, - forKey: "teamPlayerID" - ) as? String, - let gamePlayerID = coder.decodeObject( - of: NSString.self, - forKey: "gamePlayerID" - ) as? String, - let timestamp = coder.decodeObject(of: NSNumber.self, forKey: "timestamp") as? UInt64, - let displayName = coder.decodeObject( - of: NSString.self, - forKey: "displayName" - ) as? String else { - return nil - } - self.playerID = playerID - self.teamPlayerID = teamPlayerID - self.gamePlayerID = gamePlayerID - self.timestamp = timestamp - self.displayName = displayName + playerID = coder.decodeObject(of: NSString.self, forKey: "playerID") as String? + teamPlayerID = coder.decodeObject( + of: NSString.self, + forKey: "teamPlayerID" + ) as String? + gamePlayerID = coder.decodeObject( + of: NSString.self, + forKey: "gamePlayerID" + ) as String? + timestamp = coder.decodeObject(of: NSNumber.self, forKey: "timestamp") as? UInt64 + displayName = coder.decodeObject( + of: NSString.self, + forKey: "displayName" + ) as String? publicKeyURL = coder.decodeObject(forKey: "publicKeyURL") as? URL signature = coder.decodeObject(of: NSData.self, forKey: "signature") as? Data salt = coder.decodeObject(of: NSData.self, forKey: "salt") as? Data diff --git a/FirebaseAuth/Sources/Swift/AuthProvider/GitHubAuthProvider.swift b/FirebaseAuth/Sources/Swift/AuthProvider/GitHubAuthProvider.swift index 75b914cbb7a..8765acaa7db 100644 --- a/FirebaseAuth/Sources/Swift/AuthProvider/GitHubAuthProvider.swift +++ b/FirebaseAuth/Sources/Swift/AuthProvider/GitHubAuthProvider.swift @@ -36,7 +36,7 @@ import Foundation @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *) @objc(FIRGitHubAuthCredential) class GitHubAuthCredential: AuthCredential, NSSecureCoding, @unchecked Sendable { - let token: String + let token: String? init(withToken token: String) { self.token = token @@ -56,10 +56,7 @@ import Foundation } required init?(coder: NSCoder) { - guard let token = coder.decodeObject(of: NSString.self, forKey: "token") as? String else { - return nil - } - self.token = token + token = coder.decodeObject(of: NSString.self, forKey: "token") as String? super.init(provider: GitHubAuthProvider.id) } } diff --git a/FirebaseAuth/Sources/Swift/AuthProvider/GoogleAuthProvider.swift b/FirebaseAuth/Sources/Swift/AuthProvider/GoogleAuthProvider.swift index 0f41ac69ce3..38cfa40386e 100644 --- a/FirebaseAuth/Sources/Swift/AuthProvider/GoogleAuthProvider.swift +++ b/FirebaseAuth/Sources/Swift/AuthProvider/GoogleAuthProvider.swift @@ -38,8 +38,8 @@ import Foundation @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *) @objc(FIRGoogleAuthCredential) class GoogleAuthCredential: AuthCredential, NSSecureCoding, @unchecked Sendable { - let idToken: String - let accessToken: String + let idToken: String? + let accessToken: String? init(withIDToken idToken: String, accessToken: String) { self.idToken = idToken @@ -62,13 +62,8 @@ import Foundation } required init?(coder: NSCoder) { - guard let idToken = coder.decodeObject(of: NSString.self, forKey: "idToken") as? String, - let accessToken = coder.decodeObject(of: NSString.self, forKey: "accessToken") as? String - else { - return nil - } - self.idToken = idToken - self.accessToken = accessToken + idToken = coder.decodeObject(of: NSString.self, forKey: "idToken") as String? + accessToken = coder.decodeObject(of: NSString.self, forKey: "accessToken") as String? super.init(provider: GoogleAuthProvider.id) } } diff --git a/FirebaseAuth/Sources/Swift/AuthProvider/TwitterAuthProvider.swift b/FirebaseAuth/Sources/Swift/AuthProvider/TwitterAuthProvider.swift index f9c32f9d5ad..d735ee0865b 100644 --- a/FirebaseAuth/Sources/Swift/AuthProvider/TwitterAuthProvider.swift +++ b/FirebaseAuth/Sources/Swift/AuthProvider/TwitterAuthProvider.swift @@ -37,8 +37,8 @@ import Foundation @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *) @objc(FIRTwitterAuthCredential) class TwitterAuthCredential: AuthCredential, NSSecureCoding, @unchecked Sendable { - let token: String - let secret: String + let token: String? + let secret: String? init(withToken token: String, secret: String) { self.token = token @@ -61,12 +61,8 @@ import Foundation } required init?(coder: NSCoder) { - guard let token = coder.decodeObject(of: NSString.self, forKey: "token") as? String, - let secret = coder.decodeObject(of: NSString.self, forKey: "secret") as? String else { - return nil - } - self.token = token - self.secret = secret + token = coder.decodeObject(of: NSString.self, forKey: "token") as String? + secret = coder.decodeObject(of: NSString.self, forKey: "secret") as String? super.init(provider: TwitterAuthProvider.id) } } diff --git a/FirebaseAuth/Sources/Swift/Backend/RPC/SignInWithGameCenterRequest.swift b/FirebaseAuth/Sources/Swift/Backend/RPC/SignInWithGameCenterRequest.swift index 7d722326f71..34f94f87489 100644 --- a/FirebaseAuth/Sources/Swift/Backend/RPC/SignInWithGameCenterRequest.swift +++ b/FirebaseAuth/Sources/Swift/Backend/RPC/SignInWithGameCenterRequest.swift @@ -22,7 +22,7 @@ class SignInWithGameCenterRequest: IdentityToolkitRequest, AuthRPCRequest { typealias Response = SignInWithGameCenterResponse /// The playerID to verify. - var playerID: String + var playerID: String? /// The team player ID of the Game Center local player. var teamPlayerID: String? @@ -40,7 +40,7 @@ class SignInWithGameCenterRequest: IdentityToolkitRequest, AuthRPCRequest { var salt: Data /// The date and time that the signature was created. - var timestamp: UInt64 + var timestamp: UInt64? /// The STS Access Token for the authenticated user, only needed for linking the user. var accessToken: String? @@ -57,10 +57,10 @@ class SignInWithGameCenterRequest: IdentityToolkitRequest, AuthRPCRequest { /// - Parameter salt: A random string used to compute the hash and keep it randomized. /// - Parameter timestamp: The date and time that the signature was created. /// - Parameter displayName: The display name of the Game Center player. - init(playerID: String, teamPlayerID: String?, gamePlayerID: String?, + init(playerID: String?, teamPlayerID: String?, gamePlayerID: String?, publicKeyURL: URL, signature: Data, salt: Data, - timestamp: UInt64, displayName: String?, + timestamp: UInt64?, displayName: String?, requestConfiguration: AuthRequestConfiguration) { self.playerID = playerID self.teamPlayerID = teamPlayerID diff --git a/FirebaseAuth/Sources/Swift/MultiFactor/MultiFactorSession.swift b/FirebaseAuth/Sources/Swift/MultiFactor/MultiFactorSession.swift index cc83e3f2f0d..42067fd30c3 100644 --- a/FirebaseAuth/Sources/Swift/MultiFactor/MultiFactorSession.swift +++ b/FirebaseAuth/Sources/Swift/MultiFactor/MultiFactorSession.swift @@ -46,7 +46,7 @@ import Foundation return .init(idToken: currentUser.tokenService.accessToken, currentUser: currentUser) } - init(idToken: String, currentUser: User) { + init(idToken: String?, currentUser: User) { self.idToken = idToken self.currentUser = currentUser } diff --git a/FirebaseAuth/Sources/Swift/SystemService/SecureTokenService.swift b/FirebaseAuth/Sources/Swift/SystemService/SecureTokenService.swift index 6bdee4c395a..a24ce10aabc 100644 --- a/FirebaseAuth/Sources/Swift/SystemService/SecureTokenService.swift +++ b/FirebaseAuth/Sources/Swift/SystemService/SecureTokenService.swift @@ -123,7 +123,7 @@ class SecureTokenService: NSObject, NSSecureCoding { /// The cached access token. /// - /// This method is specifically for providing the access token to internal clients during + /// This method is specifically for providing the access token to internal clients during /// deserialization and sign-in events, and should not be used to retrieve the access token by /// anyone else. var accessToken: String