title: OAuth 2 bearer Authorization header
body: <p>With an update to the client's API the HTTPBasicAuthication method has been replace with a OAuth2 <code>Bearer</code> Authorization header.</p>
  
  <p>With the old API I would do the following:</p>
  
  <pre><code>NSURLCredential *credential = [NSURLCredential credentialWithUser:self.account.username 
                                                           password:self.account.token 
                                                        persistence:NSURLCredentialPersistenceForSession];
  
  NSURLProtectionSpace *space = [[NSURLProtectionSpace alloc] initWithHost:kAPIHost
                                                                      port:443
                                                                  protocol:NSURLProtectionSpaceHTTPS
                                                                     realm:@"my-api"
                                                      authenticationMethod:NSURLAuthenticationMethodHTTPBasic];
  </code></pre>
  
  <p>But this will not work with the <code>Bearer</code> header.</p>
  
  <p>Now normally I would just add the header my self by adding it like so:</p>
  
  <pre><code>NSString *authorization = [NSString stringWithFormat:@"Bearer %@",self.account.token];
  [urlRequest setValue:authorization forHTTPHeaderField:@"Authorization"];
  </code></pre>
  
  <p>But the problem with this solutions is that the API redirect most of the calls to other URLs, this has to do with security.
  After the <code>NSURLRequest</code> gets redirected the Authorization header is removed from the request and since I'm unable to add the Bearer method to the <code>NSURLCredentialStorage</code> it can't authenticate any more after being redirected.</p>
  
  <p>What would be a good solutions? I can only think to catch the redirect and modify the <code>NSURLRequest</code> so it does include the <code>Bearer</code> header. But how?</p>