@@ -153,7 +153,7 @@ - (BOOL) _configureProvider:(NSString *)providerName andConfig:(NSDictionary *)c
153
153
_callbackUrls = [arr copy ];
154
154
NSLog (@" Saved callback url: %@ in %@ " , saveCallbackUrl, _callbackUrls);
155
155
}
156
-
156
+
157
157
158
158
// Convert objects of url type
159
159
for (NSString *name in [config allKeys ]) {
@@ -354,14 +354,14 @@ - (NSDictionary *) getConfigForProvider:(NSString *)name
354
354
355
355
[manager addPending: client];
356
356
_pendingAuthentication = YES ;
357
-
357
+
358
358
NSLog (@" Calling authorizeWithUrl: %@ with callbackURL: %@ \n %@ " , providerName, callbackUrl, cfg);
359
359
360
360
[client authorizeWithUrl: providerName
361
361
url: callbackUrl
362
362
cfg: cfg
363
363
onSuccess: ^(DCTAuthAccount *account) {
364
- NSLog (@" on success called with account: %@ " , account);
364
+ NSLog (@" on success called with account: %@ " , account);
365
365
NSDictionary *accountResponse = [manager getAccountResponse: account cfg: cfg];
366
366
_pendingAuthentication = NO ;
367
367
[manager removePending: client];
@@ -443,16 +443,27 @@ - (NSDictionary *) getConfigForProvider:(NSString *)name
443
443
URL: apiUrl
444
444
items: items];
445
445
446
+ // Allow json body in POST / PUT requests
446
447
NSDictionary *body = [opts objectForKey: @" body" ];
447
448
if (body != nil ) {
449
+ NSMutableArray *items = [NSMutableArray array ];
450
+
448
451
for (NSString *key in body) {
449
- NSData *data = [[NSString stringWithFormat: @" %@ " , [body valueForKey: key]] dataUsingEncoding: NSUTF8StringEncoding];
450
- [request addMultiPartData: data withName: key type: @" application/json" ]; // TODO: How should we handle different body types?
452
+ NSString *value = [body valueForKey: key];
453
+
454
+ DCTAuthContentItem *item = [[DCTAuthContentItem alloc ] initWithName: key value: value];
455
+
456
+ if (item != nil ) {
457
+ [items addObject: item];
458
+ }
451
459
}
460
+
461
+ DCTAuthContent *content = [[DCTAuthContent alloc ] initWithEncoding: NSUTF8StringEncoding
462
+ type: DCTAuthContentTypeJSON
463
+ items: items];
464
+ [request setContent: content];
452
465
}
453
466
454
- request.account = existingAccount;
455
-
456
467
// If there are headers
457
468
NSDictionary *headers = [opts objectForKey: @" headers" ];
458
469
if (headers != nil ) {
@@ -463,6 +474,8 @@ - (NSDictionary *) getConfigForProvider:(NSString *)name
463
474
request.HTTPHeaders = existingHeaders;
464
475
}
465
476
477
+ request.account = existingAccount;
478
+
466
479
[request performRequestWithHandler: ^(DCTAuthResponse *response, NSError *error) {
467
480
if (error != nil ) {
468
481
NSDictionary *errorDict = @{
@@ -487,10 +500,9 @@ - (NSDictionary *) getConfigForProvider:(NSString *)name
487
500
488
501
// Parse XML
489
502
data = [XMLReader dictionaryForXMLData: rawData
490
- options: XMLReaderOptionsProcessNamespaces
491
- error: &err];
503
+ options: XMLReaderOptionsProcessNamespaces
504
+ error: &err];
492
505
}
493
-
494
506
if (err != nil ) {
495
507
NSDictionary *errResp = @{
496
508
@" status" : @" error" ,
@@ -500,7 +512,7 @@ - (NSDictionary *) getConfigForProvider:(NSString *)name
500
512
} else {
501
513
NSDictionary *resp = @{
502
514
@" status" : @(statusCode),
503
- @" data" : data
515
+ @" data" : data != nil ? data : @[]
504
516
};
505
517
callback (@[[NSNull null ], resp]);
506
518
}
@@ -527,7 +539,7 @@ - (DCTAuthAccount *) accountForProvider:(NSString *) providerName
527
539
}
528
540
529
541
- (NSDictionary *) credentialForAccount : (NSString *)providerName
530
- cfg : (NSDictionary *)cfg
542
+ cfg : (NSDictionary *)cfg
531
543
{
532
544
DCTAuthAccount *account = [self accountForProvider: providerName];
533
545
if (!account) {
@@ -715,3 +727,4 @@ - (NSString *) stringHost:(NSURL *)url
715
727
}
716
728
717
729
@end
730
+
0 commit comments