My organization uses several different authentication methods. One of the things I struggled with was our applications that use Oath2, which expect the authorization header to store token information in HTTP headers. I can manually put the authorization header information for each request, but I would like this information to be automatically filled in instead of manually adding it for each NSURLSession, NSURLConnection, UIWebView or [UIImage: imageFromUrl]. In the Apples documentation for the NSURLConnection and NSURLSession classes, he says that he will handle to handle various aspects of the> HTTP protocol for you, including the Authentication header, and they recommend that you do not change this property, but it does not seem to be set for me. At least I would expectthat for an NSURLSession object, I will only need to set it once by accessing sharedSession and adding header information via a call to setHTTPAdditionalHeaders, but it does not seem to store the information the next time I access sharedSession.
Am I missing something there or do I need to manually fill in the HTTP header for all calls?
EDIT:
The following is a code snippet showing how I am trying to set the title for the session.
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
id jSONObj = [defaults objectForKey: kTokenInformation];
[config setHTTPAdditionalHeaders:@{@"Authorization": [NSString stringWithFormat:@"Bearer %@",[jSONObj valueForKeyPath:@"access_token"]]}];
session = [NSURLSession sessionWithConfiguration:config];
However, it seems that the token is present on the next call to [NSURLSession sharedSession]. So now I have to do this every time I call a general session. I'm also not sure about the documentation on how you will handle applications that support multiple sessions, each of which may require separate Auth tokens. Any thoughts that I miss hear.
Daveb source
share