Skip to content

Commit 2c475ab

Browse files
committed
Enable json body parsing
1 parent e93162d commit 2c475ab

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

ios/OAuthManager/OAuthManager.m

+23-16
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ - (BOOL) _configureProvider:(NSString *)providerName andConfig:(NSDictionary *)c
153153
_callbackUrls = [arr copy];
154154
NSLog(@"Saved callback url: %@ in %@", saveCallbackUrl, _callbackUrls);
155155
}
156-
156+
157157

158158
// Convert objects of url type
159159
for (NSString *name in [config allKeys]) {
@@ -354,14 +354,14 @@ - (NSDictionary *) getConfigForProvider:(NSString *)name
354354

355355
[manager addPending:client];
356356
_pendingAuthentication = YES;
357-
357+
358358
NSLog(@"Calling authorizeWithUrl: %@ with callbackURL: %@\n %@", providerName, callbackUrl, cfg);
359359

360360
[client authorizeWithUrl:providerName
361361
url:callbackUrl
362362
cfg:cfg
363363
onSuccess:^(DCTAuthAccount *account) {
364-
NSLog(@"on success called with account: %@", account);
364+
NSLog(@"on success called with account: %@", account);
365365
NSDictionary *accountResponse = [manager getAccountResponse:account cfg:cfg];
366366
_pendingAuthentication = NO;
367367
[manager removePending:client];
@@ -444,21 +444,26 @@ - (NSDictionary *) getConfigForProvider:(NSString *)name
444444
items:items];
445445

446446
// Allow json body in POST / PUT requests
447-
448447
NSDictionary *body = [opts objectForKey:@"body"];
449448
if (body != nil) {
450-
/*for (NSString *key in body) {
449+
NSMutableArray *items = [NSMutableArray array];
450+
451+
for (NSString *key in body) {
451452
NSString *value = [body valueForKey:key];
452453

453-
if(value != nil) {
454-
[request.content.HTTPBody addObject:];
454+
DCTAuthContentItem *item = [[DCTAuthContentItem alloc] initWithName:key value:value];
455+
456+
if(item != nil) {
457+
[items addObject: item];
455458
}
456-
}*/
457-
[request.content setHTTPBody: body];
459+
}
460+
461+
DCTAuthContent *content = [[DCTAuthContent alloc] initWithEncoding:NSUTF8StringEncoding
462+
type:DCTAuthContentTypeJSON
463+
items:items];
464+
[request setContent:content];
458465
}
459466

460-
request.account = existingAccount;
461-
462467
// If there are headers
463468
NSDictionary *headers = [opts objectForKey:@"headers"];
464469
if (headers != nil) {
@@ -469,6 +474,8 @@ - (NSDictionary *) getConfigForProvider:(NSString *)name
469474
request.HTTPHeaders = existingHeaders;
470475
}
471476

477+
request.account = existingAccount;
478+
472479
[request performRequestWithHandler:^(DCTAuthResponse *response, NSError *error) {
473480
if (error != nil) {
474481
NSDictionary *errorDict = @{
@@ -493,10 +500,9 @@ - (NSDictionary *) getConfigForProvider:(NSString *)name
493500

494501
// Parse XML
495502
data = [XMLReader dictionaryForXMLData:rawData
496-
options:XMLReaderOptionsProcessNamespaces
497-
error:&err];
503+
options:XMLReaderOptionsProcessNamespaces
504+
error:&err];
498505
}
499-
500506
if (err != nil) {
501507
NSDictionary *errResp = @{
502508
@"status": @"error",
@@ -506,7 +512,7 @@ - (NSDictionary *) getConfigForProvider:(NSString *)name
506512
} else {
507513
NSDictionary *resp = @{
508514
@"status": @(statusCode),
509-
@"data": data
515+
@"data": data != nil ? data : @[]
510516
};
511517
callback(@[[NSNull null], resp]);
512518
}
@@ -533,7 +539,7 @@ - (DCTAuthAccount *) accountForProvider:(NSString *) providerName
533539
}
534540

535541
- (NSDictionary *) credentialForAccount:(NSString *)providerName
536-
cfg:(NSDictionary *)cfg
542+
cfg:(NSDictionary *)cfg
537543
{
538544
DCTAuthAccount *account = [self accountForProvider:providerName];
539545
if (!account) {
@@ -721,3 +727,4 @@ - (NSString *) stringHost:(NSURL *)url
721727
}
722728

723729
@end
730+

0 commit comments

Comments
 (0)