@@ -136,10 +136,18 @@ - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLRespon
136
136
}
137
137
138
138
NSString *authenticateHeader = nil ;
139
- if ([response isKindOfClass: [NSHTTPURLResponse class ]])
140
- authenticateHeader = [[(NSHTTPURLResponse *)response allHeaderFields ] objectForKey: @" WWW-Authenticate" ];
141
- if (self.statusCode == 401
142
- && client.accessToken .refreshToken != nil
139
+ if ([response isKindOfClass: [NSHTTPURLResponse class ]]) {
140
+ NSDictionary *headerFields = [(NSHTTPURLResponse *)response allHeaderFields ];
141
+ for (NSString *headerKey in headerFields.allKeys ) {
142
+ if ([[headerKey lowercaseString ] isEqualToString: @" www-authenticate" ]) {
143
+ authenticateHeader = [headerFields objectForKey: headerKey];
144
+ break ;
145
+ }
146
+ }
147
+ }
148
+ if (/* self.statusCode == 401 // TODO: check for status code once the bug returning 500 is fixed
149
+ &&*/ client.accessToken .refreshToken != nil
150
+ && authenticateHeader
143
151
&& [authenticateHeader rangeOfString: @" expired_token" ].location != NSNotFound ) {
144
152
[self cancel ];
145
153
[client refreshAccessTokenAndRetryConnection: self ];
@@ -200,7 +208,6 @@ - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectio
200
208
201
209
- (void )connection : (NSURLConnection *)connection didReceiveAuthenticationChallenge : (NSURLAuthenticationChallenge *)challenge ;
202
210
{
203
- NSLog (@" Auth error: " , [challenge.error localizedDescription ]);
204
211
if ([challenge.protectionSpace.authenticationMethod isEqualToString: NSURLAuthenticationMethodServerTrust ]) {
205
212
// if ([trustedHosts containsObject:challenge.protectionSpace.host])
206
213
[challenge.sender useCredential: [NSURLCredential credentialForTrust: challenge.protectionSpace.serverTrust] forAuthenticationChallenge: challenge];
0 commit comments