Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

allow changes of "headers" and "auth" in replicators #128

Merged
merged 1 commit into from

2 participants

@robin

I am using oauth2 to authenticate replications. To achieve that, I set the
'Authorization' header of replicators to 'Bearer '. It works fine
until the access token expires and I want to reset the header with a new
token. The saving is failed and I get a '403 forbidden' error.
I checked the code and found the saving failed because the replicator only
allows some of the properties to change:
NSSet* mutableProperties = [NSSet setWithObjects: @"filter",
@"query_params",
@"heartbeat", @"feed",
nil];

It should be good if we can allow the change of 'headers" and "auth"

@snej snej merged commit 4cee513 into couchbaselabs:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 1, 2012
  1. @robin
This page is out of date. Refresh to see the latest.
Showing with 28 additions and 0 deletions.
  1. +28 −0 Source/TDReplicatorManager.m
View
28 Source/TDReplicatorManager.m
@@ -215,9 +215,37 @@ - (BOOL) validateRevision: (TDRevision*)newRev context: (id<TDValidationContext>
NSSet* deletableProperties = [NSSet setWithObjects: @"_replication_state", nil];
NSSet* mutableProperties = [NSSet setWithObjects: @"filter", @"query_params",
@"heartbeat", @"feed", nil];
+ NSSet* partialMutableProperties = [NSSet setWithObjects:@"target", @"source", nil];
return [context enumerateChanges: ^BOOL(NSString *key, id oldValue, id newValue) {
if (![context currentRevision])
return ![key hasPrefix: @"_"];
+
+ // allow change of 'headers' and 'auth' in target and source
+ if ([partialMutableProperties containsObject:key]) {
+ NSDictionary *old = $castIf(NSDictionary, oldValue);
+ NSDictionary *nuu = $castIf(NSDictionary, newValue);
+ if ([oldValue isKindOfClass:[NSString class]]) {
+ old = [NSDictionary dictionaryWithObject:oldValue forKey:@"url"];
+ }
+ if ([newValue isKindOfClass:[NSString class]]) {
+ nuu = [NSDictionary dictionaryWithObject:newValue forKey:@"url"];
+ }
+ NSMutableSet* changedKeys = [[NSMutableSet alloc] init];
+ for (NSString *subKey in old.allKeys) {
+ if (!$equal([old objectForKey: subKey], [nuu objectForKey: subKey])) {
+ [changedKeys addObject:subKey];
+ }
+ }
+ for (NSString *subKey in nuu.allKeys) {
+ if (![old objectForKey:subKey]) {
+ [changedKeys addObject:subKey];
+ }
+ }
+ NSSet* mutableSubProperties = [NSSet setWithObjects:@"headers", @"auth", nil];
+ [changedKeys minusSet:mutableSubProperties];
+ return [changedKeys count] == 0;
+ }
+
NSSet* allowed = newValue ? mutableProperties : deletableProperties;
return [allowed containsObject: key];
}];
Something went wrong with that request. Please try again.