Skip to content

Commit dfab8bc

Browse files
authored
Merge pull request #108 from FirebasePrivate/fix_secure_token_crash
Fixes FIRSecureToken Crash
2 parents 0313bf7 + cd09789 commit dfab8bc

File tree

3 files changed

+43
-20
lines changed

3 files changed

+43
-20
lines changed

Firebase/Auth/Source/FIRSecureTokenService.m

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@
2020
#import "FIRAuthKeychain.h"
2121
#import "FIRAuthSerialTaskQueue.h"
2222
#import "FIRAuthBackend.h"
23+
#import "FIRAuthRequestConfiguration.h"
2324
#import "FIRSecureTokenRequest.h"
2425
#import "FIRSecureTokenResponse.h"
2526

27+
@class FIRAuthRequestConfiguration;
28+
2629
/** @var kAPIKeyCodingKey
2730
@brief The key used to encode the APIKey for NSSecureCoding.
2831
*/
@@ -57,10 +60,10 @@ - (nullable instancetype)initWithAPIKey:(NSString *)APIKey NS_DESIGNATED_INITIAL
5760
@end
5861

5962
@implementation FIRSecureTokenService {
60-
/** @var _APIKey
61-
@brief A Google API key for making Secure Token Service requests.
63+
/** @var _requestConfiguration
64+
@brief Contains configuration relevant to the request.
6265
*/
63-
NSString *_APIKey;
66+
FIRAuthRequestConfiguration *_requestConfiguration;
6467

6568
/** @var _taskQueue
6669
@brief Used to serialize all requests for access tokens.
@@ -86,7 +89,7 @@ - (instancetype)init {
8689
- (nullable instancetype)initWithAPIKey:(NSString *)APIKey {
8790
self = [super init];
8891
if (self) {
89-
_APIKey = [APIKey copy];
92+
_requestConfiguration = [[FIRAuthRequestConfiguration alloc] initWithAPIKey:APIKey];
9093
_taskQueue = [[FIRAuthSerialTaskQueue alloc] init];
9194
}
9295
return self;
@@ -160,7 +163,7 @@ - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
160163
}
161164

162165
- (void)encodeWithCoder:(NSCoder *)aCoder {
163-
[aCoder encodeObject:_APIKey forKey:kAPIKeyCodingKey];
166+
[aCoder encodeObject:_requestConfiguration.APIKey forKey:kAPIKeyCodingKey];
164167
// Authorization code is not encoded because it is not long-lived.
165168
[aCoder encodeObject:_refreshToken forKey:kRefreshTokenKey];
166169
[aCoder encodeObject:_accessToken forKey:kAccessTokenKey];
@@ -184,9 +187,11 @@ - (void)encodeWithCoder:(NSCoder *)aCoder {
184187
- (void)requestAccessToken:(FIRFetchAccessTokenCallback)callback {
185188
FIRSecureTokenRequest *request;
186189
if (_refreshToken.length) {
187-
request = [FIRSecureTokenRequest refreshRequestWithRefreshToken:_refreshToken APIKey:_APIKey];
190+
request = [FIRSecureTokenRequest refreshRequestWithRefreshToken:_refreshToken
191+
requestConfiguration:_requestConfiguration];
188192
} else {
189-
request = [FIRSecureTokenRequest authCodeRequestWithCode:_authorizationCode APIKey:_APIKey];
193+
request = [FIRSecureTokenRequest authCodeRequestWithCode:_authorizationCode
194+
requestConfiguration:_requestConfiguration];
190195
}
191196
[FIRAuthBackend secureToken:request
192197
callback:^(FIRSecureTokenResponse *_Nullable response,

Firebase/Auth/Source/RPCs/FIRSecureTokenRequest.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,22 @@ typedef NS_ENUM(NSUInteger, FIRSecureTokenRequestGrantType) {
7171
/** @fn authCodeRequestWithCode:
7272
@brief Creates an authorization code request with the given code (legacy Gitkit "ID Token").
7373
@param code The authorization code (legacy Gitkit "ID Token").
74-
@param APIKey The client's API Key.
74+
@param requestConfiguration An object containing configurations to be added to the request.
7575
@return An authorization request.
7676
*/
77-
+ (FIRSecureTokenRequest *)authCodeRequestWithCode:(NSString *)code APIKey:(NSString *)APIKey;
77+
+ (FIRSecureTokenRequest *)authCodeRequestWithCode:(NSString *)code
78+
requestConfiguration:(FIRAuthRequestConfiguration *)
79+
requestConfiguration;
7880

7981
/** @fn refreshRequestWithCode:
8082
@brief Creates a refresh request with the given refresh token.
8183
@param refreshToken The refresh token.
82-
@param APIKey The client's API Key.
84+
@param requestConfiguration An object containing configurations to be added to the request.
8385
@return A refresh request.
8486
*/
8587
+ (FIRSecureTokenRequest *)refreshRequestWithRefreshToken:(NSString *)refreshToken
86-
APIKey:(NSString *)APIKey;
88+
requestConfiguration:(FIRAuthRequestConfiguration *)
89+
requestConfiguration;
8790

8891
/** @fn init
8992
@brief Please use initWithGrantType:scope:refreshToken:code:
@@ -96,13 +99,14 @@ typedef NS_ENUM(NSUInteger, FIRSecureTokenRequestGrantType) {
9699
@param scope The scopes requested.
97100
@param refreshToken The client's refresh token (for refresh requests.)
98101
@param code The client's authorization code (Gitkit ID Token) (for authorization code requests.)
99-
@param APIKey The client's API Key.
102+
@param requestConfiguration An object containing configurations to be added to the request.
100103
*/
101104
- (nullable instancetype)initWithGrantType:(FIRSecureTokenRequestGrantType)grantType
102105
scope:(nullable NSString *)scope
103106
refreshToken:(nullable NSString *)refreshToken
104107
code:(nullable NSString *)code
105-
APIKey:(NSString *)APIKey NS_DESIGNATED_INITIALIZER;
108+
requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration
109+
NS_DESIGNATED_INITIALIZER;
106110

107111
@end
108112

Firebase/Auth/Source/RPCs/FIRSecureTokenRequest.m

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
#import "FIRSecureTokenRequest.h"
18+
#import "FIRAuthRequestConfiguration.h"
1819

1920
/** @var kFIRSecureTokenServiceGetTokenURLFormat
2021
@brief The format of the secure token service URLs. Requires string format substitution with
@@ -57,23 +58,31 @@
5758
*/
5859
static NSString *gAPIHost = @"securetoken.googleapis.com";
5960

60-
@implementation FIRSecureTokenRequest
61+
@implementation FIRSecureTokenRequest {
62+
/** @var _requestConfiguration
63+
@brief Contains configuration relevant to the request.
64+
*/
65+
FIRAuthRequestConfiguration *_requestConfiguration;
66+
}
6167

62-
+ (FIRSecureTokenRequest *)authCodeRequestWithCode:(NSString *)code APIKey:(NSString *)APIKey {
68+
+ (FIRSecureTokenRequest *)authCodeRequestWithCode:(NSString *)code
69+
requestConfiguration:(FIRAuthRequestConfiguration *)
70+
requestConfiguration {
6371
return [[self alloc] initWithGrantType:FIRSecureTokenRequestGrantTypeAuthorizationCode
6472
scope:nil
6573
refreshToken:nil
6674
code:code
67-
APIKey:APIKey];
75+
requestConfiguration:requestConfiguration];
6876
}
6977

7078
+ (FIRSecureTokenRequest *)refreshRequestWithRefreshToken:(NSString *)refreshToken
71-
APIKey:(NSString *)APIKey {
79+
requestConfiguration:(FIRAuthRequestConfiguration *)
80+
requestConfiguration {
7281
return [[self alloc] initWithGrantType:FIRSecureTokenRequestGrantTypeRefreshToken
7382
scope:nil
7483
refreshToken:refreshToken
7584
code:nil
76-
APIKey:APIKey];
85+
requestConfiguration:requestConfiguration];
7786
}
7887

7988
/** @fn grantTypeStringWithGrantType:
@@ -93,18 +102,23 @@ - (nullable instancetype)initWithGrantType:(FIRSecureTokenRequestGrantType)grant
93102
scope:(nullable NSString *)scope
94103
refreshToken:(nullable NSString *)refreshToken
95104
code:(nullable NSString *)code
96-
APIKey:(NSString *)APIKey {
105+
requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration {
97106
self = [super init];
98107
if (self) {
99108
_grantType = grantType;
100109
_scope = [scope copy];
101110
_refreshToken = [refreshToken copy];
102111
_code = [code copy];
103-
_APIKey = [APIKey copy];
112+
_APIKey = [requestConfiguration.APIKey copy];
113+
_requestConfiguration = requestConfiguration;
104114
}
105115
return self;
106116
}
107117

118+
- (FIRAuthRequestConfiguration *)requestConfiguration {
119+
return _requestConfiguration;
120+
}
121+
108122
- (NSURL *)requestURL {
109123
NSString *URLString =
110124
[NSString stringWithFormat:kFIRSecureTokenServiceGetTokenURLFormat, gAPIHost, _APIKey];

0 commit comments

Comments
 (0)