Skip to content

Commit 424c02b

Browse files
authored
[auth] Update decoders for consistency with v10 nil behavior (#14212)
1 parent 454f399 commit 424c02b

File tree

9 files changed

+39
-58
lines changed

9 files changed

+39
-58
lines changed

FirebaseAuth/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Unreleased
2+
- [fixed] Updated most decoders to be consistent with Firebase 10's behavior
3+
for decoding `nil` values. (#14212)
4+
15
# 11.6.0
26
- [added] Added reCAPTCHA Enterprise support for app verification during phone
37
authentication for Firebase Authentication (#14114)

FirebaseAuth/Sources/Swift/AuthProvider/FacebookAuthProvider.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import Foundation
3636
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
3737
@objc(FIRFacebookAuthCredential) class FacebookAuthCredential: AuthCredential, NSSecureCoding,
3838
@unchecked Sendable {
39-
let accessToken: String
39+
let accessToken: String?
4040

4141
init(withAccessToken accessToken: String) {
4242
self.accessToken = accessToken
@@ -56,11 +56,7 @@ import Foundation
5656
}
5757

5858
required init?(coder: NSCoder) {
59-
guard let accessToken = coder.decodeObject(of: NSString.self, forKey: "accessToken") as? String
60-
else {
61-
return nil
62-
}
63-
self.accessToken = accessToken
59+
accessToken = coder.decodeObject(of: NSString.self, forKey: "accessToken") as String?
6460
super.init(provider: FacebookAuthProvider.id)
6561
}
6662
}

FirebaseAuth/Sources/Swift/AuthProvider/GameCenterAuthProvider.swift

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,14 @@
130130
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
131131
@objc(FIRGameCenterAuthCredential)
132132
class GameCenterAuthCredential: AuthCredential, NSSecureCoding, @unchecked Sendable {
133-
let playerID: String
133+
let playerID: String?
134134
let teamPlayerID: String?
135135
let gamePlayerID: String?
136136
let publicKeyURL: URL?
137137
let signature: Data?
138138
let salt: Data?
139-
let timestamp: UInt64
140-
let displayName: String
139+
let timestamp: UInt64?
140+
let displayName: String?
141141

142142
/// - Parameter playerID: The ID of the Game Center local player.
143143
/// - Parameter teamPlayerID: The teamPlayerID of the Game Center local player.
@@ -177,27 +177,20 @@
177177
}
178178

179179
required init?(coder: NSCoder) {
180-
guard let playerID = coder.decodeObject(of: NSString.self, forKey: "playerID") as? String,
181-
let teamPlayerID = coder.decodeObject(
182-
of: NSString.self,
183-
forKey: "teamPlayerID"
184-
) as? String,
185-
let gamePlayerID = coder.decodeObject(
186-
of: NSString.self,
187-
forKey: "gamePlayerID"
188-
) as? String,
189-
let timestamp = coder.decodeObject(of: NSNumber.self, forKey: "timestamp") as? UInt64,
190-
let displayName = coder.decodeObject(
191-
of: NSString.self,
192-
forKey: "displayName"
193-
) as? String else {
194-
return nil
195-
}
196-
self.playerID = playerID
197-
self.teamPlayerID = teamPlayerID
198-
self.gamePlayerID = gamePlayerID
199-
self.timestamp = timestamp
200-
self.displayName = displayName
180+
playerID = coder.decodeObject(of: NSString.self, forKey: "playerID") as String?
181+
teamPlayerID = coder.decodeObject(
182+
of: NSString.self,
183+
forKey: "teamPlayerID"
184+
) as String?
185+
gamePlayerID = coder.decodeObject(
186+
of: NSString.self,
187+
forKey: "gamePlayerID"
188+
) as String?
189+
timestamp = coder.decodeObject(of: NSNumber.self, forKey: "timestamp") as? UInt64
190+
displayName = coder.decodeObject(
191+
of: NSString.self,
192+
forKey: "displayName"
193+
) as String?
201194
publicKeyURL = coder.decodeObject(forKey: "publicKeyURL") as? URL
202195
signature = coder.decodeObject(of: NSData.self, forKey: "signature") as? Data
203196
salt = coder.decodeObject(of: NSData.self, forKey: "salt") as? Data

FirebaseAuth/Sources/Swift/AuthProvider/GitHubAuthProvider.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import Foundation
3636
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
3737
@objc(FIRGitHubAuthCredential) class GitHubAuthCredential: AuthCredential, NSSecureCoding,
3838
@unchecked Sendable {
39-
let token: String
39+
let token: String?
4040

4141
init(withToken token: String) {
4242
self.token = token
@@ -56,10 +56,7 @@ import Foundation
5656
}
5757

5858
required init?(coder: NSCoder) {
59-
guard let token = coder.decodeObject(of: NSString.self, forKey: "token") as? String else {
60-
return nil
61-
}
62-
self.token = token
59+
token = coder.decodeObject(of: NSString.self, forKey: "token") as String?
6360
super.init(provider: GitHubAuthProvider.id)
6461
}
6562
}

FirebaseAuth/Sources/Swift/AuthProvider/GoogleAuthProvider.swift

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ import Foundation
3838
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
3939
@objc(FIRGoogleAuthCredential) class GoogleAuthCredential: AuthCredential, NSSecureCoding,
4040
@unchecked Sendable {
41-
let idToken: String
42-
let accessToken: String
41+
let idToken: String?
42+
let accessToken: String?
4343

4444
init(withIDToken idToken: String, accessToken: String) {
4545
self.idToken = idToken
@@ -62,13 +62,8 @@ import Foundation
6262
}
6363

6464
required init?(coder: NSCoder) {
65-
guard let idToken = coder.decodeObject(of: NSString.self, forKey: "idToken") as? String,
66-
let accessToken = coder.decodeObject(of: NSString.self, forKey: "accessToken") as? String
67-
else {
68-
return nil
69-
}
70-
self.idToken = idToken
71-
self.accessToken = accessToken
65+
idToken = coder.decodeObject(of: NSString.self, forKey: "idToken") as String?
66+
accessToken = coder.decodeObject(of: NSString.self, forKey: "accessToken") as String?
7267
super.init(provider: GoogleAuthProvider.id)
7368
}
7469
}

FirebaseAuth/Sources/Swift/AuthProvider/TwitterAuthProvider.swift

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ import Foundation
3737
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
3838
@objc(FIRTwitterAuthCredential) class TwitterAuthCredential: AuthCredential, NSSecureCoding,
3939
@unchecked Sendable {
40-
let token: String
41-
let secret: String
40+
let token: String?
41+
let secret: String?
4242

4343
init(withToken token: String, secret: String) {
4444
self.token = token
@@ -61,12 +61,8 @@ import Foundation
6161
}
6262

6363
required init?(coder: NSCoder) {
64-
guard let token = coder.decodeObject(of: NSString.self, forKey: "token") as? String,
65-
let secret = coder.decodeObject(of: NSString.self, forKey: "secret") as? String else {
66-
return nil
67-
}
68-
self.token = token
69-
self.secret = secret
64+
token = coder.decodeObject(of: NSString.self, forKey: "token") as String?
65+
secret = coder.decodeObject(of: NSString.self, forKey: "secret") as String?
7066
super.init(provider: TwitterAuthProvider.id)
7167
}
7268
}

FirebaseAuth/Sources/Swift/Backend/RPC/SignInWithGameCenterRequest.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class SignInWithGameCenterRequest: IdentityToolkitRequest, AuthRPCRequest {
2222
typealias Response = SignInWithGameCenterResponse
2323

2424
/// The playerID to verify.
25-
var playerID: String
25+
var playerID: String?
2626

2727
/// The team player ID of the Game Center local player.
2828
var teamPlayerID: String?
@@ -40,7 +40,7 @@ class SignInWithGameCenterRequest: IdentityToolkitRequest, AuthRPCRequest {
4040
var salt: Data
4141

4242
/// The date and time that the signature was created.
43-
var timestamp: UInt64
43+
var timestamp: UInt64?
4444

4545
/// The STS Access Token for the authenticated user, only needed for linking the user.
4646
var accessToken: String?
@@ -57,10 +57,10 @@ class SignInWithGameCenterRequest: IdentityToolkitRequest, AuthRPCRequest {
5757
/// - Parameter salt: A random string used to compute the hash and keep it randomized.
5858
/// - Parameter timestamp: The date and time that the signature was created.
5959
/// - Parameter displayName: The display name of the Game Center player.
60-
init(playerID: String, teamPlayerID: String?, gamePlayerID: String?,
60+
init(playerID: String?, teamPlayerID: String?, gamePlayerID: String?,
6161
publicKeyURL: URL,
6262
signature: Data, salt: Data,
63-
timestamp: UInt64, displayName: String?,
63+
timestamp: UInt64?, displayName: String?,
6464
requestConfiguration: AuthRequestConfiguration) {
6565
self.playerID = playerID
6666
self.teamPlayerID = teamPlayerID

FirebaseAuth/Sources/Swift/MultiFactor/MultiFactorSession.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import Foundation
4646
return .init(idToken: currentUser.tokenService.accessToken, currentUser: currentUser)
4747
}
4848

49-
init(idToken: String, currentUser: User) {
49+
init(idToken: String?, currentUser: User) {
5050
self.idToken = idToken
5151
self.currentUser = currentUser
5252
}

FirebaseAuth/Sources/Swift/SystemService/SecureTokenService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class SecureTokenService: NSObject, NSSecureCoding {
123123

124124
/// The cached access token.
125125
///
126-
/// This method is specifically for providing the access token to internal clients during
126+
/// This method is specifically for providing the access token to internal clients during
127127
/// deserialization and sign-in events, and should not be used to retrieve the access token by
128128
/// anyone else.
129129
var accessToken: String

0 commit comments

Comments
 (0)