Start a new topic

authorization issue

I use iOS SDK in my project, but for upload/download file use AFNetworking & REST API, because your sdk does not have cancel operation. File size can be about 1 GB.

Example: (1-st step)

KCSUser *user = [KCSUser activeUser];

NSString *authHeader = [NSString stringWithFormat:@"Kinvey %@", user.sessionAuth];

NSString *fileName = [filePath lastPathComponent];

NSNumber *fileSize = [FileManagementUtils sizeOfItemWithPath:filePath];

NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithDictionary:@{@"_filename" : fileName, @"size" : fileSize, @"mimeType" : @"binary/octet-stream"}];

NSString *domain = @"";

NSString *kinveyURL = [NSString stringWithFormat:@"%@/blob/%@", domain, kKinveyAppKey];

NSMutableURLRequest *fileCollectionRequest = [[AFHTTPRequestSerializer serializer] requestWithMethod:@"POST" URLString:kinveyURL parameters:parameters error:NULL];

[fileCollectionRequest setValue:@"3" forHTTPHeaderField:@"X-Kinvey-API-Version"];

[fileCollectionRequest setValue:authHeader forHTTPHeaderField:@"Authorization"];

AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:fileCollectionRequest];

[operation setResponseSerializer:[AFJSONResponseSerializer serializer]];

__weak RequestManager *weakSelf = self;

[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operationBlock, id responseObject) {

// handler

} failure:^(AFHTTPRequestOperation *operationBlock, NSError *error) {

// error handler


it is work fine in version 1.22.0

BUT when I updated SDK to 1.27.1 I get error every time:

Error Domain=AFNetworkingErrorDomain Code=-1011 "Request failed: not authorized (401)" UserInfo=0x186039e0 {NSErrorFailingURLKey=****HGq, AFNetworkingOperationFailingURLResponseErrorKey= { URL:****Gq } { status code: 401, headers {

Connection = "keep-alive";

"Content-Length" = 195;

"Content-Type" = "application/json; charset=utf-8";

Date = "Mon, 06 Oct 2014 10:27:29 GMT";

Server = "ngx_openresty";

"Www-Authenticate" = "Kinvey realm=\"Kinvey authorization needed\"";

"X-Kinvey-API-Version" = 3;

"X-Kinvey-Request-Id" = bb373e******147baff9e;

"X-Powered-By" = Express;

} }, NSLocalizedDescription=Request failed: not authorized (401)}

probably that the problem in user.sessionAuth

@property (nonatomic, copy) NSString *sessionAuth KCS_DEPRECATED(Token no longer stored with the user object, 1.25.0);

I don't want double login iOS SDK & REST, only iOS

How can I implement it with SDK v.1.27.1 ?

1 Comment


We don't allow access to the authtoken directly anymore for security reasons...

But, as a workaround, on your login screen-- once a user enters their credentials, can you call login on both the ios library and the rest api at the same time?
Login or Signup to post a comment