oauth 2.0 - ios7 - cannot store credentials after authentication using AFOAuthCredential -


i authenticating against mobile server using afnetworking 2.0 + groauth2sessionmanager ( includes afoauthcredential) ( security framework included ... )

on authentication success , tokens stored credentials :

    - (void)authorizeuser:(nsstring *)login password:(nsstring *)password onsuccess:(void (^)())success onfailure:(void (^)(nsstring *))failure {      nsurl *url = self.base_url;          groauth2sessionmanager *sessionmanager = [groauth2sessionmanager managerwithbaseurl:url clientid:self.client_key secret:self.client_secret];         sessionmanager.responseserializer = [afhttpresponseserializer serializer];      [sessionmanager authenticateusingoauthwithpath:self.token_path      login:login      password:password      scope:nil      success:^(afoauthcredential *credential) {          [afoauthcredential storecredential:credential                              withidentifier:[url host]];          self.creds = credential;          success();      }      failure:^(nserror *error) {          nslog(@"oauth client authorization error: %@", error);          nsdictionary *uinfo = [error userinfo];           nshttpurlresponse *response = [uinfo valueforkey:afnetworkingoperationfailingurlresponseerrorkey];          nsinteger status = response.statuscode;          if (400 <= status && status < 500) {              [self resignauthorization];          }          failure([uinfo valueforkey:nslocalizedrecoverysuggestionerrorkey]);      }]; } 

but error in console :

unable fetch credential identifier "localhost" (error -25300) 

i afoauthcredential, , can see blocks regarding security ..
did miss in app setup cope ? ...

    #ifdef _security_secitem_h_ nsstring * const kafoauth2credentialservicename = @"afoauthcredentialservice";  static nsmutabledictionary * afkeychainquerydictionarywithidentifier(nsstring *identifier) {     nsmutabledictionary *querydictionary = [nsmutabledictionary dictionarywithobjectsandkeys:(__bridge id)ksecclassgenericpassword, ksecclass, kafoauth2credentialservicename, ksecattrservice, nil];     [querydictionary setvalue:identifier forkey:(__bridge id)ksecattraccount];      return querydictionary; } #endif  ...  #pragma mark keychain  #ifdef _security_secitem_h_  + (bool)storecredential:(afoauthcredential *)credential withidentifier:(nsstring *)identifier {     return [self storecredential:credential withidentifier:identifier useicloud:no]; }  + (bool)storecredential:(afoauthcredential *)credential withidentifier:(nsstring *)identifier useicloud:(bool)shoulduseicloud {     id securityaccessibility; #if (defined(__iphone_os_version_max_allowed) && __iphone_os_version_max_allowed >= 43000) || (defined(__mac_os_x_version_max_allowed) && __mac_os_x_version_max_allowed >= 1090)     securityaccessibility = (__bridge id)ksecattraccessiblewhenunlocked; #endif     return [self storecredential:credential withidentifier:identifier withaccessibility:securityaccessibility useicloud:shoulduseicloud]; }  + (bool)storecredential:(afoauthcredential *)credential          withidentifier:(nsstring *)identifier withaccessibility:(id)securityaccessibility useicloud:(bool)shoulduseicloud {     nsmutabledictionary *querydictionary = afkeychainquerydictionarywithidentifier(identifier);      if (!credential) {         return [self deletecredentialwithidentifier:identifier useicloud:shoulduseicloud];     }      nsmutabledictionary *updatedictionary = [nsmutabledictionary dictionary];     nsdata *data = [nskeyedarchiver archiveddatawithrootobject:credential];     [updatedictionary setobject:data forkey:(__bridge id)ksecvaluedata];     if (securityaccessibility) {         [updatedictionary setobject:securityaccessibility forkey:(__bridge id)ksecattraccessible];     }      if (shoulduseicloud && &ksecattrsynchronizable != null) {         [querydictionary setobject:@yes forkey:(__bridge id)ksecattrsynchronizable];         [updatedictionary setobject:@yes forkey:(__bridge id)ksecattrsynchronizable];     }      osstatus status;     bool exists = ([self retrievecredentialwithidentifier:identifier] != nil);      if (exists) {         status = secitemupdate((__bridge cfdictionaryref)querydictionary, (__bridge cfdictionaryref)updatedictionary);     } else {         [querydictionary addentriesfromdictionary:updatedictionary];         status = secitemadd((__bridge cfdictionaryref)querydictionary, null);     }      if (status != errsecsuccess) {         nslog(@"unable %@ credential identifier \"%@\" (error %li)", exists ? @"update" : @"add", identifier, (long int)status);     }      return (status == errsecsuccess); } 

sorry , after running test once more time, realise it's running fine .... first fetch doesn't hit identifier ... credentials stored , , subsequent fetches hit stored identifier .... fault running on simulator , reseting content ....


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -