Skip to content

Commit 67038af

Browse files
authored
Remove unused STS auth code flow. (#9094)
* Remove unused STS auth code flow. * Fix unit tests.
1 parent 490c2a3 commit 67038af

File tree

5 files changed

+22
-154
lines changed

5 files changed

+22
-154
lines changed

FirebaseAuth/Sources/Backend/RPC/FIRSecureTokenRequest.h

Lines changed: 5 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -20,65 +20,22 @@
2020

2121
NS_ASSUME_NONNULL_BEGIN
2222

23-
/** @enum FIRSecureTokenRequestGrantType
24-
@brief Represents the possible grant types for a token request.
25-
*/
26-
typedef NS_ENUM(NSUInteger, FIRSecureTokenRequestGrantType) {
27-
/** @var FIRSecureTokenRequestGrantTypeAuthorizationCode
28-
@brief Indicates an authorization code request.
29-
@remarks Exchanges a Gitkit "ID Token" for an STS Access Token and Refresh Token.
30-
*/
31-
FIRSecureTokenRequestGrantTypeAuthorizationCode,
32-
33-
/** @var FIRSecureTokenRequestGrantTypeRefreshToken
34-
@brief Indicates an refresh token request.
35-
@remarks Uses an existing Refresh Token to create a new Access Token.
36-
*/
37-
FIRSecureTokenRequestGrantTypeRefreshToken,
38-
};
39-
4023
/** @class FIRSecureTokenRequest
4124
@brief Represents the parameters for the token endpoint.
4225
*/
4326
@interface FIRSecureTokenRequest : NSObject <FIRAuthRPCRequest>
4427

45-
/** @property grantType
46-
@brief The type of grant requested.
47-
@see FIRSecureTokenRequestGrantType
48-
*/
49-
@property(nonatomic, assign, readonly) FIRSecureTokenRequestGrantType grantType;
50-
51-
/** @property scope
52-
@brief The scopes requested (a comma-delimited list of scope strings.)
53-
*/
54-
@property(nonatomic, copy, readonly, nullable) NSString *scope;
55-
5628
/** @property refreshToken
5729
@brief The client's refresh token.
5830
*/
5931
@property(nonatomic, copy, readonly, nullable) NSString *refreshToken;
6032

61-
/** @property code
62-
@brief The client's authorization code (legacy Gitkit "ID Token").
63-
*/
64-
@property(nonatomic, copy, readonly, nullable) NSString *code;
65-
6633
/** @property APIKey
6734
@brief The client's API Key.
6835
*/
6936
@property(nonatomic, copy, readonly) NSString *APIKey;
7037

71-
/** @fn authCodeRequestWithCode:
72-
@brief Creates an authorization code request with the given code (legacy Gitkit "ID Token").
73-
@param code The authorization code (legacy Gitkit "ID Token").
74-
@param requestConfiguration An object containing configurations to be added to the request.
75-
@return An authorization request.
76-
*/
77-
+ (FIRSecureTokenRequest *)authCodeRequestWithCode:(NSString *)code
78-
requestConfiguration:
79-
(FIRAuthRequestConfiguration *)requestConfiguration;
80-
81-
/** @fn refreshRequestWithCode:
38+
/** @fn refreshRequestWithRefreshToken:requestConfiguration:
8239
@brief Creates a refresh request with the given refresh token.
8340
@param refreshToken The refresh token.
8441
@param requestConfiguration An object containing configurations to be added to the request.
@@ -89,23 +46,17 @@ typedef NS_ENUM(NSUInteger, FIRSecureTokenRequestGrantType) {
8946
(FIRAuthRequestConfiguration *)requestConfiguration;
9047

9148
/** @fn init
92-
@brief Please use initWithGrantType:scope:refreshToken:code:
49+
@brief Please use initWithRefreshToken:requestConfiguration:
9350
*/
9451
- (instancetype)init NS_UNAVAILABLE;
9552

96-
/** @fn initWithGrantType:scope:refreshToken:code:APIKey:
53+
/** @fn initWithRefreshToken:requestConfiguration:
9754
@brief Designated initializer.
98-
@param grantType The type of request.
99-
@param scope The scopes requested.
10055
@param refreshToken The client's refresh token (for refresh requests.)
101-
@param code The client's authorization code (Gitkit ID Token) (for authorization code requests.)
10256
@param requestConfiguration An object containing configurations to be added to the request.
10357
*/
104-
- (nullable instancetype)initWithGrantType:(FIRSecureTokenRequestGrantType)grantType
105-
scope:(nullable NSString *)scope
106-
refreshToken:(nullable NSString *)refreshToken
107-
code:(nullable NSString *)code
108-
requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration
58+
- (nullable instancetype)initWithRefreshToken:(NSString *)refreshToken
59+
requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration
10960
NS_DESIGNATED_INITIALIZER;
11061

11162
@end

FirebaseAuth/Sources/Backend/RPC/FIRSecureTokenRequest.m

Lines changed: 7 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -37,31 +37,16 @@
3737
*/
3838
static NSString *const kFIRSecureTokenServiceGrantTypeRefreshToken = @"refresh_token";
3939

40-
/** @var kFIRSecureTokenServiceGrantTypeAuthorizationCode
41-
@brief The string value of the @c FIRSecureTokenRequestGrantTypeAuthorizationCode request type.
42-
*/
43-
static NSString *const kFIRSecureTokenServiceGrantTypeAuthorizationCode = @"authorization_code";
44-
4540
/** @var kGrantTypeKey
4641
@brief The key for the "grantType" parameter in the request.
4742
*/
4843
static NSString *const kGrantTypeKey = @"grantType";
4944

50-
/** @var kScopeKey
51-
@brief The key for the "scope" parameter in the request.
52-
*/
53-
static NSString *const kScopeKey = @"scope";
54-
5545
/** @var kRefreshTokenKey
5646
@brief The key for the "refreshToken" parameter in the request.
5747
*/
5848
static NSString *const kRefreshTokenKey = @"refreshToken";
5949

60-
/** @var kCodeKey
61-
@brief The key for the "code" parameter in the request.
62-
*/
63-
static NSString *const kCodeKey = @"code";
64-
6550
/** @var gAPIHost
6651
@brief Host for server API calls.
6752
*/
@@ -74,50 +59,17 @@ @implementation FIRSecureTokenRequest {
7459
FIRAuthRequestConfiguration *_requestConfiguration;
7560
}
7661

77-
+ (FIRSecureTokenRequest *)authCodeRequestWithCode:(NSString *)code
78-
requestConfiguration:
79-
(FIRAuthRequestConfiguration *)requestConfiguration {
80-
return [[self alloc] initWithGrantType:FIRSecureTokenRequestGrantTypeAuthorizationCode
81-
scope:nil
82-
refreshToken:nil
83-
code:code
84-
requestConfiguration:requestConfiguration];
85-
}
86-
8762
+ (FIRSecureTokenRequest *)refreshRequestWithRefreshToken:(NSString *)refreshToken
8863
requestConfiguration:
8964
(FIRAuthRequestConfiguration *)requestConfiguration {
90-
return [[self alloc] initWithGrantType:FIRSecureTokenRequestGrantTypeRefreshToken
91-
scope:nil
92-
refreshToken:refreshToken
93-
code:nil
94-
requestConfiguration:requestConfiguration];
65+
return [[self alloc] initWithRefreshToken:refreshToken requestConfiguration:requestConfiguration];
9566
}
9667

97-
/** @fn grantTypeStringWithGrantType:
98-
@brief Converts a @c FIRSecureTokenRequestGrantType to it's @c NSString equivilent.
99-
*/
100-
+ (NSString *)grantTypeStringWithGrantType:(FIRSecureTokenRequestGrantType)grantType {
101-
switch (grantType) {
102-
case FIRSecureTokenRequestGrantTypeAuthorizationCode:
103-
return kFIRSecureTokenServiceGrantTypeAuthorizationCode;
104-
case FIRSecureTokenRequestGrantTypeRefreshToken:
105-
return kFIRSecureTokenServiceGrantTypeRefreshToken;
106-
// No Default case so we will notice if new grant types are added to the enum.
107-
}
108-
}
109-
110-
- (nullable instancetype)initWithGrantType:(FIRSecureTokenRequestGrantType)grantType
111-
scope:(nullable NSString *)scope
112-
refreshToken:(nullable NSString *)refreshToken
113-
code:(nullable NSString *)code
114-
requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration {
68+
- (nullable instancetype)initWithRefreshToken:(NSString *)refreshToken
69+
requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration {
11570
self = [super init];
11671
if (self) {
117-
_grantType = grantType;
118-
_scope = [scope copy];
11972
_refreshToken = [refreshToken copy];
120-
_code = [code copy];
12173
_APIKey = [requestConfiguration.APIKey copy];
12274
_requestConfiguration = requestConfiguration;
12375
}
@@ -148,17 +100,10 @@ - (BOOL)containsPostBody {
148100
}
149101

150102
- (nullable id)unencodedHTTPRequestBodyWithError:(NSError *_Nullable *_Nullable)error {
151-
NSMutableDictionary *postBody =
152-
[@{kGrantTypeKey : [[self class] grantTypeStringWithGrantType:_grantType]} mutableCopy];
153-
if (_scope) {
154-
postBody[kScopeKey] = _scope;
155-
}
156-
if (_refreshToken) {
157-
postBody[kRefreshTokenKey] = _refreshToken;
158-
}
159-
if (_code) {
160-
postBody[kCodeKey] = _code;
161-
}
103+
NSMutableDictionary *postBody = [@{
104+
kGrantTypeKey : kFIRSecureTokenServiceGrantTypeRefreshToken,
105+
kRefreshTokenKey : _refreshToken
106+
} mutableCopy];
162107
return [postBody copy];
163108
}
164109

FirebaseAuth/Sources/SystemService/FIRSecureTokenService.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,6 @@ typedef void (^FIRFetchAccessTokenCallback)(NSString *_Nullable token,
6464
*/
6565
@property(nonatomic, copy, readonly, nullable) NSDate *accessTokenExpirationDate;
6666

67-
/** @fn initWithRequestConfiguration:authorizationCode:
68-
@brief Creates a @c FIRSecureTokenService with an authroization code.
69-
@param requestConfiguration The configuration for making requests to server.
70-
@param authorizationCode An authorization code which needs to be exchanged for STS tokens.
71-
*/
72-
- (instancetype)initWithRequestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration
73-
authorizationCode:(NSString *)authorizationCode;
74-
7567
/** @fn initWithRequestConfiguration:accessToken:accessTokenExpirationDate:refreshToken
7668
@brief Creates a @c FIRSecureTokenService with access and refresh tokens.
7769
@param requestConfiguration The configuration for making requests to server.

FirebaseAuth/Sources/SystemService/FIRSecureTokenService.m

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,6 @@ @implementation FIRSecureTokenService {
6464
*/
6565
FIRAuthSerialTaskQueue *_taskQueue;
6666

67-
/** @var _authorizationCode
68-
@brief An authorization code which needs to be exchanged for Secure Token Service tokens.
69-
*/
70-
NSString *_Nullable _authorizationCode;
71-
7267
/** @var _accessToken
7368
@brief The currently cached access token. Or |nil| if no token is currently cached.
7469
*/
@@ -83,16 +78,6 @@ - (instancetype)init {
8378
return self;
8479
}
8580

86-
- (instancetype)initWithRequestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration
87-
authorizationCode:(NSString *)authorizationCode {
88-
self = [self init];
89-
if (self) {
90-
_requestConfiguration = requestConfiguration;
91-
_authorizationCode = [authorizationCode copy];
92-
}
93-
return self;
94-
}
95-
9681
- (instancetype)initWithRequestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration
9782
accessToken:(nullable NSString *)accessToken
9883
accessTokenExpirationDate:(nullable NSDate *)accessTokenExpirationDate
@@ -176,14 +161,9 @@ - (void)encodeWithCoder:(NSCoder *)aCoder {
176161
access to and mutation of these instance variables.
177162
*/
178163
- (void)requestAccessToken:(FIRFetchAccessTokenCallback)callback {
179-
FIRSecureTokenRequest *request;
180-
if (_refreshToken.length) {
181-
request = [FIRSecureTokenRequest refreshRequestWithRefreshToken:_refreshToken
182-
requestConfiguration:_requestConfiguration];
183-
} else {
184-
request = [FIRSecureTokenRequest authCodeRequestWithCode:_authorizationCode
185-
requestConfiguration:_requestConfiguration];
186-
}
164+
FIRSecureTokenRequest *request =
165+
[FIRSecureTokenRequest refreshRequestWithRefreshToken:_refreshToken
166+
requestConfiguration:_requestConfiguration];
187167
[FIRAuthBackend
188168
secureToken:request
189169
callback:^(FIRSecureTokenResponse *_Nullable response, NSError *_Nullable error) {

FirebaseAuth/Tests/Unit/FIRSecureTokenRequestTests.m

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
*/
3131
static NSString *const kFirebaseAppID = @"appID";
3232

33-
/** @var kCode
34-
@brief A testing authorization code.
33+
/** @var kRefreshToken
34+
@brief A testing refresh token.
3535
*/
36-
static NSString *const kCode = @"code";
36+
static NSString *const kRefreshToken = @"refreshToken";
3737

3838
/** @var kEmulatorHostAndPort
3939
@brief A testing emulator host and port.
@@ -56,8 +56,8 @@ - (void)testRequestURL {
5656
FIRAuthRequestConfiguration *requestConfiguration =
5757
[[FIRAuthRequestConfiguration alloc] initWithAPIKey:kAPIKey appID:kFirebaseAppID];
5858
FIRSecureTokenRequest *request =
59-
[FIRSecureTokenRequest authCodeRequestWithCode:kCode
60-
requestConfiguration:requestConfiguration];
59+
[FIRSecureTokenRequest refreshRequestWithRefreshToken:kRefreshToken
60+
requestConfiguration:requestConfiguration];
6161

6262
NSString *expectedURL =
6363
[NSString stringWithFormat:@"https://securetoken.googleapis.com/v1/token?key=%@", kAPIKey];
@@ -74,8 +74,8 @@ - (void)testRequestURLUseEmulator {
7474
[[FIRAuthRequestConfiguration alloc] initWithAPIKey:kAPIKey appID:kFirebaseAppID];
7575
requestConfiguration.emulatorHostAndPort = kEmulatorHostAndPort;
7676
FIRSecureTokenRequest *request =
77-
[FIRSecureTokenRequest authCodeRequestWithCode:kCode
78-
requestConfiguration:requestConfiguration];
77+
[FIRSecureTokenRequest refreshRequestWithRefreshToken:kRefreshToken
78+
requestConfiguration:requestConfiguration];
7979

8080
NSString *expectedURL =
8181
[NSString stringWithFormat:@"http://%@/securetoken.googleapis.com/v1/token?key=%@",

0 commit comments

Comments
 (0)