Skip to content

Commit e423eba

Browse files
author
chuanr
authored
Use team player ID, game player ID and fetchItems for signature verification (#10441)
* Initial changes * Update response * Update FIRSignInWithGameCenterRequest.m * Update FIRGameCenterAuthProvider.m * Update FIRGameCenterAuthProvider.m * Update FIRSignInWithGameCenterTests.m
1 parent a9b889d commit e423eba

10 files changed

+135
-23
lines changed

FirebaseAuth/Sources/Auth/FIRAuth.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,8 @@ - (void)signInAndRetrieveDataWithGameCenterCredential:(FIRGameCenterAuthCredenti
790790
callback:(FIRAuthDataResultCallback)callback {
791791
FIRSignInWithGameCenterRequest *request =
792792
[[FIRSignInWithGameCenterRequest alloc] initWithPlayerID:credential.playerID
793+
teamPlayerID:credential.teamPlayerID
794+
gamePlayerID:credential.gamePlayerID
793795
publicKeyURL:credential.publicKeyURL
794796
signature:credential.signature
795797
salt:credential.salt

FirebaseAuth/Sources/AuthProvider/GameCenter/FIRGameCenterAuthCredential.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ NS_ASSUME_NONNULL_BEGIN
2929
*/
3030
@property(nonatomic, readonly) NSString *playerID;
3131

32+
/** @property teamPlayerID
33+
@brief The team player ID of the Game Center local player.
34+
*/
35+
@property(nonatomic, readonly) NSString *teamPlayerID;
36+
37+
/** @property gamePlayerID
38+
@brief The game player ID of the Game Center local player.
39+
*/
40+
@property(nonatomic, readonly) NSString *gamePlayerID;
41+
3242
/** @property publicKeyURL
3343
@brief The URL for the public encryption key.
3444
*/
@@ -63,6 +73,8 @@ NS_ASSUME_NONNULL_BEGIN
6373
@param displayName The display name of the Game Center player.
6474
*/
6575
- (nullable instancetype)initWithPlayerID:(NSString *)playerID
76+
teamPlayerID:(nullable NSString *)teamPlayerID
77+
gamePlayerID:(nullable NSString *)gamePlayerID
6678
publicKeyURL:(NSURL *)publicKeyURL
6779
signature:(NSData *)signature
6880
salt:(NSData *)salt

FirebaseAuth/Sources/AuthProvider/GameCenter/FIRGameCenterAuthCredential.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ - (nullable instancetype)initWithProvider:(NSString *)provider {
3333
}
3434

3535
- (nullable instancetype)initWithPlayerID:(NSString *)playerID
36+
teamPlayerID:(nullable NSString *)teamPlayerID
37+
gamePlayerID:(nullable NSString *)gamePlayerID
3638
publicKeyURL:(NSURL *)publicKeyURL
3739
signature:(NSData *)signature
3840
salt:(NSData *)salt
@@ -41,6 +43,8 @@ - (nullable instancetype)initWithPlayerID:(NSString *)playerID
4143
self = [super initWithProvider:FIRGameCenterAuthProviderID];
4244
if (self) {
4345
_playerID = [playerID copy];
46+
_teamPlayerID = [teamPlayerID copy];
47+
_gamePlayerID = [gamePlayerID copy];
4448
_publicKeyURL = [publicKeyURL copy];
4549
_signature = [signature copy];
4650
_salt = [salt copy];
@@ -64,12 +68,16 @@ + (BOOL)supportsSecureCoding {
6468

6569
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
6670
NSString *playerID = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"playerID"];
71+
NSString *teamPlayerID = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"teamPlayerID"];
72+
NSString *gamePlayerID = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"gamePlayerID"];
6773
NSURL *publicKeyURL = [aDecoder decodeObjectOfClass:[NSURL class] forKey:@"publicKeyURL"];
6874
NSData *signature = [aDecoder decodeObjectOfClass:[NSData class] forKey:@"signature"];
6975
NSData *salt = [aDecoder decodeObjectOfClass:[NSData class] forKey:@"salt"];
7076
NSNumber *timestamp = [aDecoder decodeObjectOfClass:[NSNumber class] forKey:@"timestamp"];
7177
NSString *displayName = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"displayName"];
7278
self = [self initWithPlayerID:playerID
79+
teamPlayerID:teamPlayerID
80+
gamePlayerID:gamePlayerID
7381
publicKeyURL:publicKeyURL
7482
signature:signature
7583
salt:salt
@@ -80,6 +88,8 @@ - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
8088

8189
- (void)encodeWithCoder:(NSCoder *)aCoder {
8290
[aCoder encodeObject:self.playerID forKey:@"playerID"];
91+
[aCoder encodeObject:self.teamPlayerID forKey:@"teamPlayerID"];
92+
[aCoder encodeObject:self.gamePlayerID forKey:@"gamePlayerID"];
8393
[aCoder encodeObject:self.publicKeyURL forKey:@"publicKeyURL"];
8494
[aCoder encodeObject:self.signature forKey:@"signature"];
8595
[aCoder encodeObject:self.salt forKey:@"salt"];

FirebaseAuth/Sources/AuthProvider/GameCenter/FIRGameCenterAuthProvider.m

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -54,37 +54,61 @@ + (void)getCredentialWithCompletion:(FIRGameCenterCredentialCallback)completion
5454
}
5555
return;
5656
}
57-
58-
[localPlayer generateIdentityVerificationSignatureWithCompletionHandler:^(
59-
NSURL *publicKeyURL, NSData *signature, NSData *salt, uint64_t timestamp,
60-
NSError *error) {
61-
if (error) {
62-
if (completion) {
63-
completion(nil, error);
64-
}
65-
} else {
66-
if (completion) {
67-
/**
68-
@c `localPlayer.alias` is actually the displayname needed, instead of
69-
`localPlayer.displayname`. For more information, check
70-
https://developer.apple.com/documentation/gamekit/gkplayer
71-
**/
72-
NSString *displayName = localPlayer.alias;
73-
// iOS 13 deprecation
74-
#pragma clang diagnostic push
75-
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
57+
if (@available(iOS 13.5, macOS 10.15.5, macCatalyst 13.5, tvOS 13.4.8, *)) {
58+
[localPlayer fetchItemsForIdentityVerificationSignature:^(
59+
NSURL *_Nullable publicKeyURL, NSData *_Nullable signature,
60+
NSData *_Nullable salt, uint64_t timestamp, NSError *_Nullable error) {
61+
if (error) {
62+
if (completion) {
63+
completion(nil, error);
64+
}
65+
} else {
7666
FIRGameCenterAuthCredential *credential =
7767
[[FIRGameCenterAuthCredential alloc] initWithPlayerID:localPlayer.playerID
68+
teamPlayerID:localPlayer.teamPlayerID
69+
gamePlayerID:localPlayer.gamePlayerID
7870
publicKeyURL:publicKeyURL
7971
signature:signature
8072
salt:salt
8173
timestamp:timestamp
82-
displayName:displayName];
83-
#pragma clang diagnostic pop
74+
displayName:localPlayer.displayName];
8475
completion(credential, nil);
8576
}
86-
}
87-
}];
77+
}];
78+
} else {
79+
[localPlayer generateIdentityVerificationSignatureWithCompletionHandler:^(
80+
NSURL *publicKeyURL, NSData *signature, NSData *salt, uint64_t timestamp,
81+
NSError *error) {
82+
if (error) {
83+
if (completion) {
84+
completion(nil, error);
85+
}
86+
} else {
87+
if (completion) {
88+
/**
89+
@c `localPlayer.alias` is actually the displayname needed, instead of
90+
`localPlayer.displayname`. For more information, check
91+
https://developer.apple.com/documentation/gamekit/gkplayer
92+
**/
93+
NSString *displayName = localPlayer.alias;
94+
// iOS 13 deprecation
95+
#pragma clang diagnostic push
96+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
97+
FIRGameCenterAuthCredential *credential =
98+
[[FIRGameCenterAuthCredential alloc] initWithPlayerID:localPlayer.playerID
99+
teamPlayerID:nil
100+
gamePlayerID:nil
101+
publicKeyURL:publicKeyURL
102+
signature:signature
103+
salt:salt
104+
timestamp:timestamp
105+
displayName:displayName];
106+
#pragma clang diagnostic pop
107+
completion(credential, nil);
108+
}
109+
}
110+
}];
111+
}
88112
}
89113

90114
@end

FirebaseAuth/Sources/Backend/RPC/FIRSignInWithGameCenterRequest.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ NS_ASSUME_NONNULL_BEGIN
3131
*/
3232
@property(nonatomic, copy) NSString *playerID;
3333

34+
/** @property teamPlayerID
35+
@brief The team player ID of the Game Center local player.
36+
*/
37+
@property(nonatomic, readonly) NSString *teamPlayerID;
38+
39+
/** @property gamePlayerID
40+
@brief The game player ID of the Game Center local player.
41+
*/
42+
@property(nonatomic, readonly) NSString *gamePlayerID;
43+
3444
/** @property publicKeyURL
3545
@brief The URL for the public encryption key.
3646
*/
@@ -78,6 +88,8 @@ NS_ASSUME_NONNULL_BEGIN
7888
@param displayName The display name of the Game Center player.
7989
*/
8090
- (nullable instancetype)initWithPlayerID:(NSString *)playerID
91+
teamPlayerID:(nullable NSString *)teamPlayerID
92+
gamePlayerID:(nullable NSString *)gamePlayerID
8193
publicKeyURL:(NSURL *)publicKeyURL
8294
signature:(NSData *)signature
8395
salt:(NSData *)salt

FirebaseAuth/Sources/Backend/RPC/FIRSignInWithGameCenterRequest.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
@implementation FIRSignInWithGameCenterRequest
2929

3030
- (nullable instancetype)initWithPlayerID:(NSString *)playerID
31+
teamPlayerID:(nullable NSString *)teamPlayerID
32+
gamePlayerID:(nullable NSString *)gamePlayerID
3133
publicKeyURL:(NSURL *)publicKeyURL
3234
signature:(NSData *)signature
3335
salt:(NSData *)salt
@@ -38,6 +40,8 @@ - (nullable instancetype)initWithPlayerID:(NSString *)playerID
3840
requestConfiguration:requestConfiguration];
3941
if (self) {
4042
_playerID = playerID;
43+
_teamPlayerID = [teamPlayerID copy];
44+
_gamePlayerID = [gamePlayerID copy];
4145
_publicKeyURL = [publicKeyURL copy];
4246
_signature = [signature copy];
4347
_salt = [salt copy];
@@ -54,6 +58,12 @@ - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *__autoreleasing _Null
5458
if (_playerID) {
5559
postBody[@"playerId"] = _playerID;
5660
}
61+
if (_teamPlayerID) {
62+
postBody[@"teamPlayerId"] = _teamPlayerID;
63+
}
64+
if (_gamePlayerID) {
65+
postBody[@"gamePlayerId"] = _gamePlayerID;
66+
}
5767
if (_publicKeyURL) {
5868
postBody[@"publicKeyUrl"] = _publicKeyURL.absoluteString;
5969
}

FirebaseAuth/Sources/Backend/RPC/FIRSignInWithGameCenterResponse.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ NS_ASSUME_NONNULL_BEGIN
4444
*/
4545
@property(nonatomic, copy, readonly, nullable) NSString *playerID;
4646

47+
/** @property teamPlayerID
48+
@breif @breif The verified team player ID.
49+
*/
50+
@property(nonatomic, copy, readonly, nullable) NSString *teamPlayerID;
51+
52+
/** @property gamePlayerID
53+
@breif @breif The verified game player ID.
54+
*/
55+
@property(nonatomic, copy, readonly, nullable) NSString *gamePlayerID;
56+
4757
/** @property approximateExpirationDate
4858
@breif The approximate expiration date of the access token.
4959
*/

FirebaseAuth/Sources/Backend/RPC/FIRSignInWithGameCenterResponse.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ - (BOOL)setWithDictionary:(NSDictionary *)dictionary error:(NSError *_Nullable *
3030
[NSDate dateWithTimeIntervalSinceNow:[dictionary[@"expiresIn"] integerValue]];
3131
}
3232
_playerID = [dictionary[@"playerId"] copy];
33+
_teamPlayerID = [dictionary[@"teamPlayerId"] copy];
34+
_gamePlayerID = [dictionary[@"gamePlayerId"] copy];
3335
_isNewUser = [dictionary[@"isNewUser"] boolValue];
3436
_displayName = [dictionary[@"displayName"] copy];
3537
return YES;

FirebaseAuth/Sources/User/FIRUser.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,8 @@ - (void)linkWithCredential:(FIRAuthCredential *)credential
11811181
FIRAuthRequestConfiguration *requestConfiguration = self.auth.requestConfiguration;
11821182
FIRSignInWithGameCenterRequest *gameCenterRequest = [[FIRSignInWithGameCenterRequest alloc]
11831183
initWithPlayerID:gameCenterCredential.playerID
1184+
teamPlayerID:gameCenterCredential.teamPlayerID
1185+
gamePlayerID:gameCenterCredential.gamePlayerID
11841186
publicKeyURL:gameCenterCredential.publicKeyURL
11851187
signature:gameCenterCredential.signature
11861188
salt:gameCenterCredential.salt

FirebaseAuth/Tests/Unit/FIRSignInWithGameCenterTests.m

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,26 @@
7878
*/
7979
static NSString *const kPlayerID = @"PLAYERID";
8080

81+
/** @var kTeamPlayerIDKey
82+
@brief The key of team player id.
83+
*/
84+
static NSString *const kTeamPlayerIDKey = @"teamPlayerId";
85+
86+
/** @var kPlayerID
87+
@brief The testing player id.
88+
*/
89+
static NSString *const kTeamPlayerID = @"TEAMPLAYERID";
90+
91+
/** @var kGamePlayerIDKey
92+
@brief The key of game player id.
93+
*/
94+
static NSString *const kGamePlayerIDKey = @"gamePlayerId";
95+
96+
/** @var kGamePlayerID
97+
@brief The testing game player id.
98+
*/
99+
static NSString *const kGamePlayerID = @"GAMEPLAYERID";
100+
81101
/** @var kApproximateExpirationDateKey
82102
@brief The approximate expiration date key.
83103
*/
@@ -198,6 +218,8 @@ - (void)testRequestResponseEncoding {
198218
NSData *salt = [[NSData alloc] initWithBase64EncodedString:kSalt options:0];
199219
FIRSignInWithGameCenterRequest *request =
200220
[[FIRSignInWithGameCenterRequest alloc] initWithPlayerID:kPlayerID
221+
teamPlayerID:kTeamPlayerID
222+
gamePlayerID:kGamePlayerID
201223
publicKeyURL:[NSURL URLWithString:kPublicKeyURL]
202224
signature:signature
203225
salt:salt
@@ -221,6 +243,8 @@ - (void)testRequestResponseEncoding {
221243
XCTAssertEqualObjects(self.RPCIssuer.requestURL.absoluteString, kExpectedAPIURL);
222244
XCTAssertNotNil(self.RPCIssuer.decodedRequest);
223245
XCTAssertEqualObjects(self.RPCIssuer.decodedRequest[kPlayerIDKey], kPlayerID);
246+
XCTAssertEqualObjects(self.RPCIssuer.decodedRequest[kTeamPlayerIDKey], kTeamPlayerID);
247+
XCTAssertEqualObjects(self.RPCIssuer.decodedRequest[kGamePlayerIDKey], kGamePlayerID);
224248
XCTAssertEqualObjects(self.RPCIssuer.decodedRequest[kPublicKeyURLKey], kPublicKeyURL);
225249
XCTAssertEqualObjects(self.RPCIssuer.decodedRequest[kSignatureKey], kSignature);
226250
XCTAssertEqualObjects(self.RPCIssuer.decodedRequest[kSaltKey], kSalt);
@@ -234,6 +258,8 @@ - (void)testRequestResponseEncoding {
234258
@"refreshToken" : kRefreshToken,
235259
@"localId" : kLocalID,
236260
@"playerId" : kPlayerID,
261+
@"teamPlayerId" : kTeamPlayerID,
262+
@"gamePlayerId" : kGamePlayerID,
237263
@"expiresIn" : kApproximateExpirationDate,
238264
@"isNewUser" : [NSNumber numberWithBool:kIsNewUser],
239265
@"displayName" : kDisplayName,
@@ -246,6 +272,8 @@ - (void)testRequestResponseEncoding {
246272
XCTAssertEqualObjects(RPCResponse.refreshToken, kRefreshToken);
247273
XCTAssertEqualObjects(RPCResponse.localID, kLocalID);
248274
XCTAssertEqualObjects(RPCResponse.playerID, kPlayerID);
275+
XCTAssertEqualObjects(RPCResponse.teamPlayerID, kTeamPlayerID);
276+
XCTAssertEqualObjects(RPCResponse.gamePlayerID, kGamePlayerID);
249277
XCTAssertEqual(RPCResponse.isNewUser, kIsNewUser);
250278
XCTAssertEqualObjects(RPCResponse.displayName, kDisplayName);
251279
}

0 commit comments

Comments
 (0)