Note that there are some explanatory texts on larger screens.

plurals
  1. POPUT operation response not being saved in Core Data Store
    primarykey
    data
    text
    <p>I'm trying to authenticate a user with github using RestKit and saving the response back to Core data to hang on to the oauth token. The response is coming back with a 200 or 201 which is good, but nothing is saved back to the context. I assume that there is something small that I am missing, but I can't figure it out. Here's what's going on:</p> <p>This happens in viewDidLoad</p> <pre><code>RKObjectManager *objectManager = [RKObjectManager sharedManager]; RKManagedObjectStore *managedObjectStore = [RKManagedObjectStore defaultStore]; RKEntityMapping *entityMapping = [RKEntityMapping mappingForEntityForName:@"SLAuthentication" inManagedObjectStore:managedObjectStore]; NSString *clientID = [(SLAppDelegate *)[[UIApplication sharedApplication] delegate] clientID]; [entityMapping addAttributeMappingsFromDictionary:@{@"id" : @"tokenID", @"url" : @"url", @"token" : @"oauthToken", @"note" : @"note"}]; entityMapping.identificationAttributes = @[@"tokenID"]; RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:entityMapping method:RKRequestMethodPUT pathPattern:[NSString stringWithFormat:@"/authorizations/clients/%@", clientID] keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]; [objectManager addResponseDescriptor:responseDescriptor]; </code></pre> <p>Here's where the request is made</p> <pre><code>NSManagedObjectContext *context = [[[RKObjectManager sharedManager] managedObjectStore] mainQueueManagedObjectContext]; NSString *secret = [(SLAppDelegate *)[[UIApplication sharedApplication] delegate] clientSecret]; NSString *clientID = [(SLAppDelegate *) [[UIApplication sharedApplication] delegate] clientID]; [[RKObjectManager sharedManager].HTTPClient setAuthorizationHeaderWithUsername:userName password:pass]; [[RKObjectManager sharedManager] setRequestSerializationMIMEType:@"application/json"]; [[RKObjectManager sharedManager] putObject:nil path :[NSString stringWithFormat:@"/authorizations/clients/%@", clientID] parameters:@{@"client_secret": secret, @"scopes" : @[@"repo"]} success:nil failure:nil]; //Flush the username and password so that we aren't storing them anymore. [[RKObjectManager sharedManager].HTTPClient clearAuthorizationHeader]; NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:@"SLUser"]; NSError *error = nil; NSArray *users = [context executeFetchRequest:request error:&amp;error]; [[users firstObject] setUserName:userName]; [context save:&amp;error]; </code></pre> <p>But nothing comes back. The description of the API is here: <a href="http://developer.github.com/v3/oauth/#get-or-create-an-authorization-for-a-specific-app" rel="nofollow">http://developer.github.com/v3/oauth/#get-or-create-an-authorization-for-a-specific-app</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload