ios - NSURLCredentialStorage default credential not used automatically -


i'm switching nsurlconnection nsurlsession app communications and, while i'm @ it, trying move delegated authentication utilising nsurlcredentialstorage. i've moved on code i'm getting -urlsession:task:didreceivechallenge being called on delegate despite having set defaultcredentials on sharedcredentialstorage when app launches.

the protection spaces identical (the 1 created when setting credentials , ones passed nsurlauthenticationchallenge) per below logged messages:

register credentials for: <nsurlprotectionspace: 0x162227c0>: host:192.168.1.99, server:https, auth-scheme:nsurlauthenticationmethoddefault, realm:192.168.1.99, port:23650, proxy:no, proxy-type:(null) unexpected authentication challenge: <nsurlprotectionspace: 0x1680ee40>: host:192.168.1.99, server:https, auth-scheme:nsurlauthenticationmethoddefault, realm:192.168.1.99, port:23650, proxy:no, proxy-type:(null) 

and during didreceivechallenge:(nsurlauthenticationchallenge*)challenge delegate method:

po [[nsurlcredentialstorage sharedcredentialstorage] defaultcredentialforprotectionspace:[challenge protectionspace]] 

results in

<nsurlcredential: 0x1680ff00>: thecorrectusername 

https://stackoverflow.com/a/501869/563905 indicates that, when server responds 401 challenge, nsurlconnection (is nsurlsession problem?) first checks headers authorization (there aren't set) , consults nsurlcredentialstorage credentials protection space.

i don't understand why i'm getting didreceivechallenge delegate being called? when don't have delegate method set nsurlsession resends request without credentials... i'm stumped...

edit: i've added manual credential handling didreceivechallenge: method , it's being triggered every request despite single nsurlsession being used.

i having same problem urlsession not use stored credentials. read reference docs nsurlsession. says if you're implementing custom delegate have handle stuff when delegate methods called. in other words saving credentials half battle. receiving challenge every time server requires authentication in didreceivechallenge method have manually extract credentials use , pass them completion handler. let me know if makes sense.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

django - CSRF verification failed. Request aborted. CSRF cookie not set -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -