Skip to content

Commit b31f574

Browse files
committed
Post rebase updates for #10805 and #10441
1 parent 1d86793 commit b31f574

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+200
-85
lines changed

FirebaseAuth/Sources/Auth/FIRAuth.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,9 @@ - (nullable instancetype)initWithAPIKey:(NSString *)APIKey
460460
_listenerHandles = [NSMutableArray array];
461461
_requestConfiguration = [[FIRAuthRequestConfiguration alloc] initWithAPIKey:APIKey
462462
appID:appID
463-
auth:self
464-
heartbeatLogger:heartbeatLogger];
463+
auth:self];
464+
// TODO: heartbeat
465+
// heartbeatLogger:heartbeatLogger];
465466
_firebaseAppName = [appName copy];
466467
#if TARGET_OS_IOS
467468
_settings = [[FIRAuthSettings alloc] init];

FirebaseAuth/Sources/MultiFactor/FIRMultiFactorResolver+Internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ NS_ASSUME_NONNULL_BEGIN
2626

2727
- (instancetype)initWithMFAPendingCredential:(NSString *_Nullable)MFAPendingCredential
2828
hints:(NSArray<FIRMultiFactorInfo *> *)hints
29-
auth:(FIRAuth *)auth;
29+
auth:(FIRAuth *_Nullable)auth;
3030

3131
@end
3232

FirebaseAuth/Sources/MultiFactor/FIRMultiFactorResolver.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ @implementation FIRMultiFactorResolver
3232

3333
- (instancetype)initWithMFAPendingCredential:(NSString *_Nullable)MFAPendingCredential
3434
hints:(NSArray<FIRMultiFactorInfo *> *)hints
35-
auth:(FIRAuth *)auth {
35+
auth:(FIRAuth *_Nullable)auth {
3636
self = [super init];
3737
if (self) {
3838
_MFAPendingCredential = MFAPendingCredential;

FirebaseAuth/Sources/Swift/AuthProvider/GameCenterAuthProvider.swift

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,63 @@
2727
@brief Creates an `AuthCredential` for a Game Center sign in.
2828
*/
2929
open class func getCredential(completion: @escaping (AuthCredential?, Error?) -> Void) {
30-
// TODO: Linking GameKit.framework without using it on macOS results in App Store rejection.
30+
/**
31+
Linking GameKit.framework without using it on macOS results in App Store rejection.
32+
Thus we don't link GameKit.framework to our SDK directly. `optionalLocalPlayer` is used for
33+
checking whether the APP that consuming our SDK has linked GameKit.framework. If not, a
34+
`GameKitNotLinkedError` will be raised.
35+
**/
36+
guard let _: AnyClass = NSClassFromString("GKLocalPlayer") else {
37+
completion(nil, AuthErrorUtils.gameKitNotLinkedError())
38+
return
39+
}
40+
3141
let localPlayer = GKLocalPlayer.local
32-
if !localPlayer.isAuthenticated {
33-
// TODO: pass right error
34-
completion(nil, nil)
42+
guard localPlayer.isAuthenticated else {
43+
completion(nil, AuthErrorUtils.localPlayerNotAuthenticatedError())
3544
return
3645
}
37-
localPlayer
38-
.generateIdentityVerificationSignature { publicKeyURL, signature, salt, timestamp, error in
39-
if error != nil {
46+
47+
if #available(iOS 13.5, macOS 10.15.5, macCatalyst 13.5, tvOS 13.4.8, *) {
48+
localPlayer.fetchItems { publicKeyURL, signature, salt, timestamp, error in
49+
if let error = error {
4050
completion(nil, error)
4151
} else {
42-
/**
43-
@c `localPlayer.alias` is actually the displayname needed, instead of
44-
`localPlayer.displayname`. For more information, check
45-
https://developer.apple.com/documentation/gamekit/gkplayer
46-
**/
47-
let displayName = localPlayer.alias
4852
let credential = GameCenterAuthCredential(withPlayerID: localPlayer.playerID,
53+
teamPlayerID: localPlayer.teamPlayerID,
54+
gamePlayerID: localPlayer.gamePlayerID,
4955
publicKeyURL: publicKeyURL,
5056
signature: signature,
5157
salt: salt,
5258
timestamp: timestamp,
53-
displayName: displayName)
59+
displayName: localPlayer.displayName)
5460
completion(credential, nil)
5561
}
5662
}
63+
} else {
64+
localPlayer
65+
.generateIdentityVerificationSignature { publicKeyURL, signature, salt, timestamp, error in
66+
if error != nil {
67+
completion(nil, error)
68+
} else {
69+
/**
70+
@c `localPlayer.alias` is actually the displayname needed, instead of
71+
`localPlayer.displayname`. For more information, check
72+
https://developer.apple.com/documentation/gamekit/gkplayer
73+
**/
74+
let displayName = localPlayer.alias
75+
let credential = GameCenterAuthCredential(withPlayerID: localPlayer.playerID,
76+
teamPlayerID: nil,
77+
gamePlayerID: nil,
78+
publicKeyURL: publicKeyURL,
79+
signature: signature,
80+
salt: salt,
81+
timestamp: timestamp,
82+
displayName: displayName)
83+
completion(credential, nil)
84+
}
85+
}
86+
}
5787
}
5888

5989
/** @fn
@@ -77,6 +107,8 @@
77107
@objc(FIRGameCenterAuthCredential) public class GameCenterAuthCredential: AuthCredential,
78108
NSSecureCoding {
79109
@objc public let playerID: String
110+
@objc public let teamPlayerID: String?
111+
@objc public let gamePlayerID: String?
80112
@objc public let publicKeyURL: URL?
81113
@objc public let signature: Data?
82114
@objc public let salt: Data?
@@ -86,15 +118,20 @@
86118
/**
87119
@brief Designated initializer.
88120
@param playerID The ID of the Game Center local player.
121+
@param teamPlayerID The teamPlayerID of the Game Center local player.
122+
@param gamePlayerID The gamePlayerID of the Game Center local player.
89123
@param publicKeyURL The URL for the public encryption key.
90124
@param signature The verification signature generated.
91125
@param salt A random string used to compute the hash and keep it randomized.
92126
@param timestamp The date and time that the signature was created.
93127
@param displayName The display name of the Game Center player.
94128
*/
95-
init(withPlayerID playerID: String, publicKeyURL: URL?, signature: Data?, salt: Data?,
129+
init(withPlayerID playerID: String, teamPlayerID: String?, gamePlayerID: String?,
130+
publicKeyURL: URL?, signature: Data?, salt: Data?,
96131
timestamp: UInt64, displayName: String) {
97132
self.playerID = playerID
133+
self.teamPlayerID = teamPlayerID
134+
self.gamePlayerID = gamePlayerID
98135
self.publicKeyURL = publicKeyURL
99136
self.signature = signature
100137
self.salt = salt
@@ -107,6 +144,8 @@
107144

108145
public func encode(with coder: NSCoder) {
109146
coder.encode("playerID")
147+
coder.encode("teamPlayerID")
148+
coder.encode("gamePlayerID")
110149
coder.encode("publicKeyURL")
111150
coder.encode("signature")
112151
coder.encode("salt")
@@ -116,11 +155,15 @@
116155

117156
public required init?(coder: NSCoder) {
118157
guard let playerID = coder.decodeObject(forKey: "playerID") as? String,
158+
let teamPlayerID = coder.decodeObject(forKey: "teamPlayerID") as? String,
159+
let gamePlayerID = coder.decodeObject(forKey: "gamePlayerID") as? String,
119160
let timestamp = coder.decodeObject(forKey: "timestamp") as? UInt64,
120161
let displayName = coder.decodeObject(forKey: "displayName") as? String else {
121162
return nil
122163
}
123164
self.playerID = playerID
165+
self.teamPlayerID = teamPlayerID
166+
self.gamePlayerID = gamePlayerID
124167
self.timestamp = timestamp
125168
self.displayName = displayName
126169
publicKeyURL = coder.decodeObject(forKey: "publicKeyURL") as? URL

FirebaseAuth/Sources/Swift/Backend/AuthBackend.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,11 @@ private class AuthBackendRPCImplementation: NSObject, AuthBackendImplementation
170170
post(withRequest: request, response: response) { error in
171171
if let error = error {
172172
callback(nil, error)
173-
} else if let mfaError = AuthBackendRPCImplementation.generateMFAError(response: response) {
173+
} else if let mfaError = AuthBackendRPCImplementation.generateMFAError(response: response,
174+
auth: request
175+
.requestConfiguration(
176+
)
177+
.auth) {
174178
callback(nil, mfaError)
175179
} else {
176180
callback(response, nil)
@@ -179,7 +183,7 @@ private class AuthBackendRPCImplementation: NSObject, AuthBackendImplementation
179183
}
180184

181185
#if os(iOS)
182-
private class func generateMFAError(response: AuthRPCResponse) -> Error? {
186+
private class func generateMFAError(response: AuthRPCResponse, auth: Auth?) -> Error? {
183187
if let mfaResponse = response as? EmailLinkSignInResponse,
184188
mfaResponse.IDToken == nil,
185189
let enrollments = mfaResponse.MFAInfo {
@@ -189,14 +193,15 @@ private class AuthBackendRPCImplementation: NSObject, AuthBackendImplementation
189193
}
190194
return AuthErrorUtils.secondFactorRequiredError(
191195
pendingCredential: mfaResponse.MFAPendingCredential,
192-
hints: info
196+
hints: info,
197+
auth: auth
193198
)
194199
} else {
195200
return nil
196201
}
197202
}
198203
#else
199-
private class func generateMFAError(response: AuthRPCResponse) -> Error? {
204+
private class func generateMFAError(response: AuthRPCResponse, auth: Auth?) -> Error? {
200205
return nil
201206
}
202207
#endif

FirebaseAuth/Sources/Swift/Backend/AuthRequestConfiguration.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ import Foundation
3333
// @brief The Firebase appID used in the request.
3434
// */
3535
@objc public var appID: String
36+
37+
/** @property auth
38+
@brief The FIRAuth instance used in the request.
39+
*/
40+
@objc public weak var auth: Auth?
3641
//
3742
/// ** @property heartbeatLogger
3843
// @brief The heartbeat logger used to add heartbeats to the corresponding request's header.
@@ -55,9 +60,10 @@ import Foundation
5560
@brief Designated initializer.
5661
@param APIKey The API key to be used in the request.
5762
*/
58-
@objc public init(APIKey: String, appID: String) {
63+
@objc public init(APIKey: String, appID: String, auth: Auth? = nil) {
5964
self.APIKey = APIKey
6065
self.appID = appID
66+
self.auth = auth
6167
}
6268

6369
// TODO:

FirebaseAuth/Sources/Swift/Backend/IdentityToolkitRequest.swift

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// limitations under the License.
1414

1515
import Foundation
16-
@_implementationOnly import FirebaseCore
1716

1817
private let kHttpsProtocol = "https:"
1918
private let kHttpProtocol = "http:"
@@ -46,7 +45,7 @@ private let kIdentityPlatformStagingAPIHost =
4645
/** @property tenantID
4746
@brief The tenant ID of the request. nil if none is available.
4847
*/
49-
var tenantID: String?
48+
@objc public let tenantID: String?
5049

5150
let _requestConfiguration: AuthRequestConfiguration
5251

@@ -61,16 +60,7 @@ private let kIdentityPlatformStagingAPIHost =
6160
_requestConfiguration = requestConfiguration
6261
_useIdentityPlatform = useIdentityPlatform
6362
_useStaging = useStaging
64-
65-
// TODO: tenantID should be set via a parameter, since it might not be the default app (#10748)
66-
// TODO: remove FirebaseCore import when #10748 is fixed.
67-
// Automatically set the tenant ID. If the request is initialized before FIRAuth is configured,
68-
// set tenant ID to nil.
69-
if FirebaseApp.app() == nil {
70-
tenantID = nil
71-
} else {
72-
tenantID = Auth.auth().tenantID
73-
}
63+
tenantID = requestConfiguration.auth?.tenantID
7464
}
7565

7666
@objc public func containsPostBody() -> Bool {

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ public class SignInWithGameCenterRequest: IdentityToolkitRequest,
2727
*/
2828
@objc public var playerID: String
2929

30+
/** @property teamPlayerID
31+
@brief The team player ID of the Game Center local player.
32+
*/
33+
@objc public var teamPlayerID: String?
34+
35+
/** @property gamePlayerID
36+
@brief The game player ID of the Game Center local player.
37+
*/
38+
@objc public var gamePlayerID: String?
39+
3040
/** @property publicKeyURL
3141
@brief The URL for the public encryption key.
3242
*/
@@ -65,16 +75,22 @@ public class SignInWithGameCenterRequest: IdentityToolkitRequest,
6575
/** @fn initWithPlayerID:publicKeyURL:signature:salt:timestamp:displayName:requestConfiguration:
6676
@brief Designated initializer.
6777
@param playerID The ID of the Game Center player.
78+
@param teamPlayerID The teamPlayerID of the Game Center local player.
79+
@param gamePlayerID The gamePlayerID of the Game Center local player.
6880
@param publicKeyURL The URL for the public encryption key.
6981
@param signature The verification signature generated.
7082
@param salt A random string used to compute the hash and keep it randomized.
7183
@param timestamp The date and time that the signature was created.
7284
@param displayName The display name of the Game Center player.
7385
*/
74-
@objc public init(playerID: String, publicKeyURL: URL, signature: Data, salt: Data,
86+
@objc public init(playerID: String, teamPlayerID: String?, gamePlayerID: String?,
87+
publicKeyURL: URL,
88+
signature: Data, salt: Data,
7589
timestamp: UInt64, displayName: String?,
7690
requestConfiguration: AuthRequestConfiguration) {
7791
self.playerID = playerID
92+
self.teamPlayerID = teamPlayerID
93+
self.gamePlayerID = gamePlayerID
7894
self.publicKeyURL = publicKeyURL
7995
self.signature = signature
8096
self.salt = salt
@@ -96,6 +112,12 @@ public class SignInWithGameCenterRequest: IdentityToolkitRequest,
96112
if timestamp != 0 {
97113
postBody["timestamp"] = timestamp
98114
}
115+
if let teamPlayerID {
116+
postBody["teamPlayerId"] = teamPlayerID
117+
}
118+
if let gamePlayerID {
119+
postBody["gamePlayerId"] = gamePlayerID
120+
}
99121
if let accessToken {
100122
postBody["idToken"] = accessToken
101123
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import Foundation
2020
@objc public var refreshToken: String?
2121
@objc public var localID: String?
2222
@objc public var playerID: String?
23+
@objc public var teamPlayerID: String?
24+
@objc public var gamePlayerID: String?
2325
@objc public var approximateExpirationDate: Date?
2426
@objc public var isNewUser: Bool = false
2527
@objc public var displayName: String?
@@ -35,6 +37,8 @@ import Foundation
3537
}
3638
refreshToken = dictionary["refreshToken"] as? String
3739
playerID = dictionary["playerId"] as? String
40+
teamPlayerID = dictionary["teamPlayerId"] as? String
41+
gamePlayerID = dictionary["gamePlayerId"] as? String
3842
isNewUser = dictionary["isNewUser"] as? Bool ?? false
3943
displayName = dictionary["displayName"] as? String
4044
}

FirebaseAuth/Sources/Swift/Utilities/AuthErrorUtils.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,13 +547,15 @@ private let kFIRAuthErrorMessageMalformedJWT =
547547
#if os(iOS)
548548
// TODO(ncooke3): Address the optionality of these arguments.
549549
@objc public static func secondFactorRequiredError(pendingCredential: String?,
550-
hints: [MultiFactorInfo]?)
550+
hints: [MultiFactorInfo]?,
551+
auth: Auth?)
551552
-> Error {
552553
var userInfo: [String: Any] = [:]
553554
if let pendingCredential = pendingCredential, let hints = hints {
554555
let resolver = MultiFactorResolver(
555556
mfaPendingCredential: pendingCredential,
556-
hints: hints
557+
hints: hints,
558+
auth: auth
557559
)
558560
userInfo[FIRAuthErrorUserInfoMultiFactorResolverKey] = resolver
559561
}

0 commit comments

Comments
 (0)