Skip to content

Commit 9888eee

Browse files
authored
Merge pull request #697 from zapcannon87/master
feat: user retrieve short token
2 parents 16d701b + d59ce32 commit 9888eee

File tree

7 files changed

+118
-7
lines changed

7 files changed

+118
-7
lines changed

AVOS/LeanCloudObjcTests/BaseTestCase.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ class BaseTestCase: XCTestCase {
5454
// serverURL: "https://beta.leancloud.cn",
5555
masterKey: "Q26gTodbyi1Ki7lM9vtncF6U,master")
5656

57+
static let tds1App = AppInfo(
58+
id: "7DY3DVgOQogGnYMMUajgvPRq-TjsS5DXC",
59+
key: "RJOLaAvGiF7mQguXp68W9Mv5",
60+
serverURL: "https://7DY3DVgO.cloud.tds1.tapapis.cn",
61+
masterKey: "3PSWpjByenawCVo0FpnXfNgx")
62+
5763
static let ceApp = AppInfo(
5864
id: "skhiVsqIk7NLVdtHaUiWn0No-9Nh9j0Va",
5965
key: "T3TEAIcL8Ls5XGPsGz41B1bz",
@@ -68,6 +74,7 @@ class BaseTestCase: XCTestCase {
6874

6975
static let appInfoTable = [
7076
cnApp.id : cnApp,
77+
tds1App.id : tds1App,
7178
ceApp.id : ceApp,
7279
usApp.id : usApp,
7380
]

AVOS/Sources/Foundation/Request/LCPaasClient.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,19 @@ FOUNDATION_EXPORT NSString * const LCHeaderFieldNameProduction;
5959
- (void)getObject:(NSString *)path
6060
withParameters:(NSDictionary *)parameters
6161
block:(LCIdResultBlock)block;
62+
- (void)getObject:(NSString *)path
63+
paddingVersion:(BOOL)paddingVersion
64+
withParameters:(NSDictionary *)parameters
65+
block:(LCIdResultBlock)block;
6266
- (void)getObject:(NSString *)path
6367
withParameters:(NSDictionary *)parameters
6468
block:(LCIdResultBlock)block
6569
wait:(BOOL)wait;
70+
- (void)getObject:(NSString *)path
71+
paddingVersion:(BOOL)paddingVersion
72+
withParameters:(NSDictionary *)parameters
73+
block:(LCIdResultBlock)block
74+
wait:(BOOL)wait;
6675
- (void)getObject:(NSString *)path
6776
withParameters:(NSDictionary *)parameters
6877
policy:(LCCachePolicy)policy
@@ -117,6 +126,12 @@ FOUNDATION_EXPORT NSString * const LCHeaderFieldNameProduction;
117126
headers:(NSDictionary *)headers
118127
parameters:(id)parameters;
119128

129+
- (NSMutableURLRequest *)requestWithPath:(NSString *)path
130+
method:(NSString *)method
131+
headers:(NSDictionary *)headers
132+
parameters:(id)parameters
133+
paddingVersion:(BOOL)paddingVersion;
134+
120135
- (void)performRequest:(NSURLRequest *)request
121136
success:(void (^)(NSHTTPURLResponse *response, id responseObject))successBlock
122137
failure:(void (^)(NSHTTPURLResponse *response, id responseObject, NSError *error))failureBlock;

AVOS/Sources/Foundation/Request/LCPaasClient.m

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,22 @@ - (NSMutableURLRequest *)requestWithPath:(NSString *)path
214214
method:(NSString *)method
215215
headers:(NSDictionary *)headers
216216
parameters:(id)parameters
217+
{
218+
return [self requestWithPath:path method:method headers:headers parameters:parameters paddingVersion:true];
219+
}
220+
221+
- (NSMutableURLRequest *)requestWithPath:(NSString *)path
222+
method:(NSString *)method
223+
headers:(NSDictionary *)headers
224+
parameters:(id)parameters
225+
paddingVersion:(BOOL)paddingVersion
217226
{
218227
NSURL *URL = [NSURL URLWithString:path];
219228

220229
if (!URL.scheme.length) {
221-
NSString *URLString = [[LCRouter sharedInstance] appURLForPath:path appID:[LCApplication getApplicationId]];
230+
NSString *URLString = [[LCRouter sharedInstance] appURLForPath:path
231+
appID:[LCApplication getApplicationId]
232+
paddingVersion:paddingVersion];
222233
URL = [NSURL URLWithString:URLString];
223234
}
224235

@@ -258,21 +269,72 @@ - (NSMutableURLRequest *)requestWithPath:(NSString *)path
258269
return request;
259270
}
260271

261-
- (void)getObject:(NSString *)path withParameters:(NSDictionary *)parameters block:(LCIdResultBlock)block {
262-
[self getObject:path withParameters:parameters block:block wait:false];
272+
- (void)getObject:(NSString *)path
273+
withParameters:(NSDictionary *)parameters
274+
block:(LCIdResultBlock)block {
275+
[self getObject:path
276+
paddingVersion:true
277+
withParameters:parameters
278+
block:block];
279+
}
280+
281+
- (void)getObject:(NSString *)path
282+
paddingVersion:(BOOL)paddingVersion
283+
withParameters:(NSDictionary *)parameters
284+
block:(LCIdResultBlock)block {
285+
[self getObject:path
286+
paddingVersion:paddingVersion
287+
withParameters:parameters
288+
block:block
289+
wait:false];
263290
}
264291

265-
- (void)getObject:(NSString *)path withParameters:(NSDictionary *)parameters block:(LCIdResultBlock)block wait:(BOOL)wait {
266-
[self getObjectFromNetworkWithPath:path withParameters:parameters policy:kLCCachePolicyIgnoreCache block:block wait:wait];
292+
- (void)getObject:(NSString *)path
293+
withParameters:(NSDictionary *)parameters
294+
block:(LCIdResultBlock)block
295+
wait:(BOOL)wait {
296+
[self getObjectFromNetworkWithPath:path
297+
withParameters:parameters
298+
policy:kLCCachePolicyIgnoreCache
299+
block:block
300+
wait:wait];
301+
}
302+
303+
- (void)getObject:(NSString *)path
304+
paddingVersion:(BOOL)paddingVersion
305+
withParameters:(NSDictionary *)parameters
306+
block:(LCIdResultBlock)block
307+
wait:(BOOL)wait {
308+
[self getObjectFromNetworkWithPath:path
309+
paddingVersion:paddingVersion
310+
withParameters:parameters
311+
policy:kLCCachePolicyIgnoreCache
312+
block:block
313+
wait:wait];
314+
}
315+
316+
- (void)getObjectFromNetworkWithPath:(NSString *)path
317+
withParameters:(NSDictionary *)parameters
318+
policy:(LCCachePolicy)policy
319+
block:(LCIdResultBlock)block
320+
wait:(BOOL)wait
321+
{
322+
[self getObjectFromNetworkWithPath:path
323+
paddingVersion:true
324+
withParameters:parameters
325+
policy:policy
326+
block:block
327+
wait:wait];
267328
}
268329

269330
- (void)getObjectFromNetworkWithPath:(NSString *)path
331+
paddingVersion:(BOOL)paddingVersion
270332
withParameters:(NSDictionary *)parameters
271333
policy:(LCCachePolicy)policy
272334
block:(LCIdResultBlock)block
273335
wait:(BOOL)wait
274336
{
275-
NSURLRequest *request = [self requestWithPath:path method:@"GET" headers:nil parameters:parameters];
337+
NSURLRequest *request = [self requestWithPath:path method:@"GET" headers:nil parameters:parameters paddingVersion:paddingVersion];
276338

277339
if (parameters && request.URL.absoluteString.length > 4096) {
278340
/* If GET request too heavy, wrap it into a POST request and ignore cache policy. */

AVOS/Sources/Foundation/Router/LCRouter.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ - (void)tryUpdateAppRouterWithAppID:(NSString *)appID callback:(void (^)(NSError
228228
}
229229

230230
- (NSString *)appURLForPath:(NSString *)path appID:(NSString *)appID
231+
{
232+
return [self appURLForPath:path appID:appID paddingVersion:true];
233+
}
234+
235+
- (NSString *)appURLForPath:(NSString *)path appID:(NSString *)appID paddingVersion:(BOOL)paddingVersion
231236
{
232237
NSParameterAssert(path);
233238
NSParameterAssert(appID);
@@ -238,7 +243,7 @@ - (NSString *)appURLForPath:(NSString *)path appID:(NSString *)appID
238243
if ([serverKey isEqualToString:RouterKeyAppRTMRouterServer]) {
239244
return absoluteURLStringWithHostAndPath(host, path);
240245
} else {
241-
return absoluteURLStringWithHostAndPath(host, pathWithVersion(path));
246+
return absoluteURLStringWithHostAndPath(host, paddingVersion ? pathWithVersion(path) : path);
242247
}
243248
};
244249

AVOS/Sources/Foundation/Router/LCRouter_Internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ static RouterKey RouterKeyRTMServer = @"server";
6363

6464
- (NSString *)appURLForPath:(NSString *)path appID:(NSString *)appID;
6565

66+
- (NSString *)appURLForPath:(NSString *)path appID:(NSString *)appID paddingVersion:(BOOL)paddingVersion;
67+
6668
- (void)getRTMURLWithAppID:(NSString *)appID callback:(void (^)(NSDictionary *dictionary, NSError *error))callback;
6769

6870
- (NSString *)batchPathForPath:(NSString *)path;

AVOS/Sources/Foundation/User/LCUser.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,10 @@ FOUNDATION_EXPORT LeanCloudSocialPlatform const LeanCloudSocialPlatformWeiXin;
509509
+ (void)strictlyFindWithQuery:(LCQuery *)query
510510
callback:(void (^)(NSArray<LCUser *> * _Nullable users, NSError * _Nullable error))callback;
511511

512+
// MARK: Misc
513+
514+
+ (void)retrieveShortTokenWithCallback:(void (^)(NSString * _Nullable jwt, NSError * _Nullable error))callback;
515+
512516
@end
513517

514518
/**

AVOS/Sources/Foundation/User/LCUser.m

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,22 @@ + (void)strictlyFindWithQuery:(LCQuery *)query
12151215
}];
12161216
}
12171217

1218+
// MARK: Misc
1219+
1220+
+ (void)retrieveShortTokenWithCallback:(void (^)(NSString * _Nullable, NSError * _Nullable))callback
1221+
{
1222+
[[LCPaasClient sharedInstance] getObject:@"/storage/1.1/users/tap-support/identity"
1223+
paddingVersion:false
1224+
withParameters:nil
1225+
block:^(id _Nullable object, NSError * _Nullable error) {
1226+
if (error) {
1227+
[LCUtils callStringResultBlock:callback string:nil error:error];
1228+
} else {
1229+
[LCUtils callStringResultBlock:callback string:((NSDictionary *)object)[@"identityToken"] error:nil];
1230+
}
1231+
}];
1232+
}
1233+
12181234
#pragma mark - Override from LCObject
12191235

12201236
/**

0 commit comments

Comments
 (0)