Skip to content

Commit 1e0b4b8

Browse files
author
George Villasboas
committed
Wiring up the custom http headers for all types of requests
1 parent d0d98f1 commit 1e0b4b8

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

Sources/OAuth2Client/NXOAuth2Account.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ - (NXOAuth2Client *)oauthClient;
9292
NSString *tokenType = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationTokenType];
9393
NSString *keychainGroup = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationTokenType];
9494
NSDictionary *additionalQueryParams = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationAdditionalAuthenticationParameters];
95+
NSDictionary *customHeaderFields = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationCustomHeaderFields];
9596

9697
oauthClient = [[NXOAuth2Client alloc] initWithClientID:clientID
9798
clientSecret:clientSecret
@@ -106,6 +107,10 @@ - (NXOAuth2Client *)oauthClient;
106107
oauthClient.additionalAuthenticationParameters = additionalQueryParams;
107108
}
108109

110+
if (customHeaderFields) {
111+
oauthClient.customHeaderFields = customHeaderFields;
112+
}
113+
109114
}
110115
}
111116
return oauthClient;

Sources/OAuth2Client/NXOAuth2AccountStore.m

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -426,14 +426,13 @@ - (NXOAuth2Client *)pendingOAuthClientForAccountType:(NSString *)accountType;
426426
NSAssert([additionalAuthenticationParameters isKindOfClass:[NSDictionary class]], @"additionalAuthenticationParameters have to be a NSDictionary");
427427
client.additionalAuthenticationParameters = additionalAuthenticationParameters;
428428
}
429+
if (customHeaderFields) {
430+
client.customHeaderFields = customHeaderFields;
431+
}
429432

430433
if (scope != nil) {
431434
client.desiredScope = scope;
432435
}
433-
434-
if (customHeaderFields) {
435-
client.customHeaderFields = customHeaderFields;
436-
}
437436

438437
[self.pendingOAuthClients setObject:client forKey:accountType];
439438
}
@@ -517,7 +516,9 @@ - (void)oauthClientDidLoseAccessToken:(NXOAuth2Client *)client;
517516
NSString *accountType;
518517
@synchronized (self.pendingOAuthClients) {
519518
accountType = [self accountTypeOfPendingOAuthClient:client];
520-
[self.pendingOAuthClients removeObjectForKey:accountType];
519+
if (accountType) {
520+
[self.pendingOAuthClients removeObjectForKey:accountType];
521+
}
521522
}
522523
}
523524

Sources/OAuth2Client/NXOAuth2Client.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,12 @@ - (void)requestTokenWithAuthGrant:(NSString *)authGrant redirectURL:(NSURL *)red
330330
[parameters setObject:[[self.desiredScope allObjects] componentsJoinedByString:@" "] forKey:@"scope"];
331331
}
332332

333+
if (self.customHeaderFields) {
334+
[self.customHeaderFields enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *obj, BOOL *stop) {
335+
[tokenRequest addValue:obj forHTTPHeaderField:key];
336+
}];
337+
}
338+
333339
if (self.additionalAuthenticationParameters) {
334340
[parameters addEntriesFromDictionary:self.additionalAuthenticationParameters];
335341
}
@@ -360,6 +366,13 @@ - (void)authenticateWithClientCredentials;
360366
if (self.desiredScope) {
361367
[parameters setObject:[[self.desiredScope allObjects] componentsJoinedByString:@" "] forKey:@"scope"];
362368
}
369+
370+
if (self.customHeaderFields) {
371+
[self.customHeaderFields enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *obj, BOOL *stop) {
372+
[tokenRequest addValue:obj forHTTPHeaderField:key];
373+
}];
374+
}
375+
363376
authConnection = [[NXOAuth2Connection alloc] initWithRequest:tokenRequest
364377
requestParameters:parameters
365378
oauthClient:self

0 commit comments

Comments
 (0)