Skip to content

Commit a3dfe08

Browse files
author
Chuan Ren
authored
Support NSSecureCoding for auth credentials (#2242)
1 parent ab962ce commit a3dfe08

18 files changed

+182
-11
lines changed

Example/Auth/Sample/MainViewController.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2310,11 +2310,11 @@ - (void)getUserTokenResultWithForce:(BOOL)force {
23102310
}
23112311

23122312
/** @fn getAppTokenWithForce:
2313-
@brief Gets the token from @c FIRApp , optionally a refreshed one.
2313+
@brief Gets the token from @c FIRAuth , optionally a refreshed one.
23142314
@param force Whether the refresh is forced or not.
23152315
*/
23162316
- (void)getAppTokenWithForce:(BOOL)force {
2317-
[[FIRApp defaultApp] getTokenForcingRefresh:force withCallback:[self tokenCallback]];
2317+
[[FIRAuth auth] getTokenForcingRefresh:force withCallback:[self tokenCallback]];
23182318
}
23192319

23202320
/** @fn setDisplayName

Firebase/Auth/Source/AuthProviders/EmailPassword/FIREmailPasswordAuthCredential.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ NS_ASSUME_NONNULL_BEGIN
2323
/** @class FIREmailPasswordAuthCredential
2424
@brief Internal implementation of FIRAuthCredential for Email/Password credentials.
2525
*/
26-
@interface FIREmailPasswordAuthCredential : FIRAuthCredential
26+
@interface FIREmailPasswordAuthCredential : FIRAuthCredential <NSSecureCoding>
2727

2828
/** @property email
2929
@brief The user's email address.

Firebase/Auth/Source/AuthProviders/EmailPassword/FIREmailPasswordAuthCredential.m

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,30 @@ - (void)prepareVerifyAssertionRequest:(FIRVerifyAssertionRequest *)request {
5757
@"Attempt to call prepareVerifyAssertionRequest: on a FIREmailPasswordAuthCredential."];
5858
}
5959

60+
#pragma mark - NSSecureCoding
61+
62+
+ (BOOL)supportsSecureCoding {
63+
return YES;
64+
}
65+
66+
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
67+
NSString *email = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"email"];
68+
NSString *password = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"password"];
69+
NSString *link = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"link"];
70+
if (email.length && password.length) {
71+
self = [self initWithEmail:email password:password];
72+
} else if (email.length && link.length) {
73+
self = [self initWithEmail:email link:link];
74+
} else {
75+
self = nil;
76+
}
77+
return self;
78+
}
79+
80+
- (void)encodeWithCoder:(NSCoder *)aCoder {
81+
[aCoder encodeObject:self.email forKey:@"email"];
82+
[aCoder encodeObject:self.password forKey:@"password"];
83+
[aCoder encodeObject:self.link forKey:@"link"];
84+
}
85+
6086
@end

Firebase/Auth/Source/AuthProviders/Facebook/FIRFacebookAuthCredential.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ NS_ASSUME_NONNULL_BEGIN
2323
/** @class FIRFacebookAuthCredential
2424
@brief Internal implementation of FIRAuthCredential for the Facebook IdP.
2525
*/
26-
@interface FIRFacebookAuthCredential : FIRAuthCredential
26+
@interface FIRFacebookAuthCredential : FIRAuthCredential <NSSecureCoding>
2727

2828
/** @fn initWithAccessToken:
2929
@brief Designated initializer.

Firebase/Auth/Source/AuthProviders/Facebook/FIRFacebookAuthCredential.m

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,20 @@ - (void)prepareVerifyAssertionRequest:(FIRVerifyAssertionRequest *)request {
4848
request.providerAccessToken = _accessToken;
4949
}
5050

51+
#pragma mark - NSSecureCoding
52+
53+
+ (BOOL)supportsSecureCoding {
54+
return YES;
55+
}
56+
57+
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
58+
NSString *accessToken = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"accessToken"];
59+
self = [self initWithAccessToken:accessToken];
60+
return self;
61+
}
62+
63+
- (void)encodeWithCoder:(NSCoder *)aCoder {
64+
[aCoder encodeObject:_accessToken forKey:@"accessToken"];
65+
}
66+
5167
@end

Firebase/Auth/Source/AuthProviders/GameCenter/FIRGameCenterAuthCredential.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ NS_ASSUME_NONNULL_BEGIN
2323
/** @class FIRGameCenterAuthCredential
2424
@brief Internal implementation of FIRAuthCredential for Game Center credentials.
2525
*/
26-
@interface FIRGameCenterAuthCredential : FIRAuthCredential
26+
@interface FIRGameCenterAuthCredential : FIRAuthCredential <NSSecureCoding>
2727

2828
/** @property playerID
2929
@brief The ID of the Game Center local player.

Firebase/Auth/Source/AuthProviders/GameCenter/FIRGameCenterAuthCredential.m

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,35 @@ - (void)prepareVerifyAssertionRequest:(FIRVerifyAssertionRequest *)request {
5252
@"Attempt to call prepareVerifyAssertionRequest: on a FIRGameCenterAuthCredential."];
5353
}
5454

55+
#pragma mark - NSSecureCoding
56+
57+
+ (BOOL)supportsSecureCoding {
58+
return YES;
59+
}
60+
61+
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
62+
NSString *playerID = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"playerID"];
63+
NSURL *publicKeyURL = [aDecoder decodeObjectOfClass:[NSURL class] forKey:@"publicKeyURL"];
64+
NSData *signature = [aDecoder decodeObjectOfClass:[NSData class] forKey:@"signature"];
65+
NSData *salt = [aDecoder decodeObjectOfClass:[NSData class] forKey:@"salt"];
66+
NSNumber *timestamp = [aDecoder decodeObjectOfClass:[NSNumber class] forKey:@"timestamp"];
67+
NSString *displayName = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"displayName"];
68+
self = [self initWithPlayerID:playerID
69+
publicKeyURL:publicKeyURL
70+
signature:signature
71+
salt:salt
72+
timestamp:timestamp.unsignedLongLongValue
73+
displayName:displayName];
74+
return self;
75+
}
76+
77+
- (void)encodeWithCoder:(NSCoder *)aCoder {
78+
[aCoder encodeObject:self.playerID forKey:@"playerID"];
79+
[aCoder encodeObject:self.publicKeyURL forKey:@"publicKeyURL"];
80+
[aCoder encodeObject:self.signature forKey:@"signature"];
81+
[aCoder encodeObject:self.salt forKey:@"salt"];
82+
[aCoder encodeObject:[NSNumber numberWithUnsignedLongLong:self.timestamp] forKey:@"timestamp"];
83+
[aCoder encodeObject:self.displayName forKey:@"displayName"];
84+
}
85+
5586
@end

Firebase/Auth/Source/AuthProviders/GitHub/FIRGitHubAuthCredential.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ NS_ASSUME_NONNULL_BEGIN
2323
/** @class FIRGitHubAuthCredential
2424
@brief Internal implementation of FIRAuthCredential for GitHub credentials.
2525
*/
26-
@interface FIRGitHubAuthCredential : FIRAuthCredential
26+
@interface FIRGitHubAuthCredential : FIRAuthCredential <NSSecureCoding>
2727

2828
/** @property token
2929
@brief The GitHub OAuth access token.

Firebase/Auth/Source/AuthProviders/GitHub/FIRGitHubAuthCredential.m

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,20 @@ - (void)prepareVerifyAssertionRequest:(FIRVerifyAssertionRequest *)request {
4646
request.providerAccessToken = _token;
4747
}
4848

49+
#pragma mark - NSSecureCoding
50+
51+
+ (BOOL)supportsSecureCoding {
52+
return YES;
53+
}
54+
55+
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
56+
NSString *token = [aDecoder decodeObjectOfClass:[NSString class] forKey:@"token"];
57+
self = [self initWithToken:token];
58+
return self;
59+
}
60+
61+
- (void)encodeWithCoder:(NSCoder *)aCoder {
62+
[aCoder encodeObject:self.token forKey:@"token"];
63+
}
64+
4965
@end

Firebase/Auth/Source/AuthProviders/Google/FIRGoogleAuthCredential.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ NS_ASSUME_NONNULL_BEGIN
2323
/** @class FIRGoogleAuthCredential
2424
@brief Internal implementation of FIRAuthCredential for the Google IdP.
2525
*/
26-
@interface FIRGoogleAuthCredential : FIRAuthCredential
26+
@interface FIRGoogleAuthCredential : FIRAuthCredential <NSSecureCoding>
2727

2828
/** @fn initWithIDToken:accessToken:
2929
@brief Designated initializer.

0 commit comments

Comments
 (0)