Skip to content

Commit d999989

Browse files
airdrummingfooltoto
authored andcommitted
Adding the ability to configure the token request HTTP Method, e.g. for LinkedIn who wants all request params in the query string (and accepts GET requests).
1 parent dc453a0 commit d999989

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

Sources/OAuth2Client/NXOAuth2AccountStore.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ extern NSString * const kNXOAuth2AccountStoreConfigurationTokenURL;
3434
extern NSString * const kNXOAuth2AccountStoreConfigurationRedirectURL;
3535
extern NSString * const kNXOAuth2AccountStoreConfigurationScope;
3636
extern NSString * const kNXOAuth2AccountStoreConfigurationTokenType;
37+
extern NSString * const kNXOAuth2AccountStoreConfigurationTokenRequestHTTPMethod;
3738

3839

3940
/*

Sources/OAuth2Client/NXOAuth2AccountStore.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
NSString * const kNXOAuth2AccountStoreConfigurationRedirectURL = @"kNXOAuth2AccountStoreConfigurationRedirectURL";
4343
NSString * const kNXOAuth2AccountStoreConfigurationScope = @"kNXOAuth2AccountStoreConfigurationScope";
4444
NSString * const kNXOAuth2AccountStoreConfigurationTokenType = @"kNXOAuth2AccountStoreConfigurationTokenType";
45+
NSString * const kNXOAuth2AccountStoreConfigurationTokenRequestHTTPMethod = @"kNXOAuth2AccountStoreConfigurationTokenRequestHTTPMethod";
4546
NSString * const kNXOAuth2AccountStoreConfigurationAdditionalAuthenticationParameters = @"kNXOAuth2AccountStoreConfigurationAdditionalAuthenticationParameters";
4647

4748
#pragma mark Account Type
@@ -395,6 +396,7 @@ - (NXOAuth2Client *)pendingOAuthClientForAccountType:(NSString *)accountType;
395396
NSURL *authorizeURL = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationAuthorizeURL];
396397
NSURL *tokenURL = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationTokenURL];
397398
NSString *tokenType = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationTokenType];
399+
NSString *tokenRequestHTTPMethod = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationTokenRequestHTTPMethod];
398400
NSDictionary *additionalAuthenticationParameters = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationAdditionalAuthenticationParameters];
399401

400402
client = [[NXOAuth2Client alloc] initWithClientID:clientID
@@ -408,6 +410,9 @@ - (NXOAuth2Client *)pendingOAuthClientForAccountType:(NSString *)accountType;
408410

409411
client.persistent = NO;
410412

413+
if (tokenRequestHTTPMethod != nil) {
414+
client.tokenRequestHTTPMethod = tokenRequestHTTPMethod;
415+
}
411416
if (additionalAuthenticationParameters != nil) {
412417
NSAssert([additionalAuthenticationParameters isKindOfClass:[NSDictionary class]], @"additionalAuthenticationParameters have to be a NSDictionary");
413418
client.additionalAuthenticationParameters = additionalAuthenticationParameters;

Sources/OAuth2Client/NXOAuth2Client.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ extern NSString * const NXOAuth2ClientConnectionContextTokenRefresh;
6666
@property (nonatomic, strong, readwrite) NSDictionary *additionalAuthenticationParameters;
6767

6868
@property (nonatomic, copy) NSSet *desiredScope;
69+
@property (nonatomic, copy) NSString *tokenRequestHTTPMethod; // defaults to POST
6970
@property (nonatomic, copy) NSString *userAgent;
7071
@property (nonatomic, copy) NSString *acceptType; // defaults to application/json
7172

Sources/OAuth2Client/NXOAuth2Client.m

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ - (id)initWithClientID:(NSString *)aClientId
9191
tokenType = [aTokenType copy];
9292
accessToken = anAccessToken;
9393

94+
self.tokenRequestHTTPMethod = @"POST";
9495
self.acceptType = @"application/json";
9596

9697
self.persistent = shouldPersist;
@@ -308,7 +309,7 @@ - (void)requestTokenWithAuthGrant:(NSString *)authGrant redirectURL:(NSURL *)red
308309
NSAssert1(!authConnection, @"authConnection already running with: %@", authConnection);
309310

310311
NSMutableURLRequest *tokenRequest = [NSMutableURLRequest requestWithURL:tokenURL];
311-
[tokenRequest setHTTPMethod:@"POST"];
312+
[tokenRequest setHTTPMethod:self.tokenRequestHTTPMethod];
312313
[authConnection cancel]; // just to be sure
313314

314315
self.authenticating = YES;
@@ -341,7 +342,7 @@ - (void)authenticateWithClientCredentials;
341342
NSAssert1(!authConnection, @"authConnection already running with: %@", authConnection);
342343

343344
NSMutableURLRequest *tokenRequest = [NSMutableURLRequest requestWithURL:tokenURL];
344-
[tokenRequest setHTTPMethod:@"POST"];
345+
[tokenRequest setHTTPMethod:self.tokenRequestHTTPMethod];
345346
[authConnection cancel]; // just to be sure
346347

347348
self.authenticating = YES;
@@ -367,7 +368,7 @@ - (void)authenticateWithUsername:(NSString *)username password:(NSString *)passw
367368
NSAssert1(!authConnection, @"authConnection already running with: %@", authConnection);
368369

369370
NSMutableURLRequest *tokenRequest = [NSMutableURLRequest requestWithURL:tokenURL];
370-
[tokenRequest setHTTPMethod:@"POST"];
371+
[tokenRequest setHTTPMethod:self.tokenRequestHTTPMethod];
371372
[authConnection cancel]; // just to be sure
372373

373374
self.authenticating = YES;
@@ -402,7 +403,7 @@ - (void)authenticateWithAssertionType:(NSURL *)anAssertionType assertion:(NSStri
402403
NSParameterAssert(anAssertion);
403404

404405
NSMutableURLRequest *tokenRequest = [NSMutableURLRequest requestWithURL:tokenURL];
405-
[tokenRequest setHTTPMethod:@"POST"];
406+
[tokenRequest setHTTPMethod:self.tokenRequestHTTPMethod];
406407
[authConnection cancel]; // just to be sure
407408

408409
self.authenticating = YES;
@@ -440,7 +441,7 @@ - (void)refreshAccessTokenAndRetryConnection:(NXOAuth2Connection *)retryConnecti
440441
if (!authConnection) {
441442
NSAssert((accessToken.refreshToken != nil), @"invalid state");
442443
NSMutableURLRequest *tokenRequest = [NSMutableURLRequest requestWithURL:tokenURL];
443-
[tokenRequest setHTTPMethod:@"POST"];
444+
[tokenRequest setHTTPMethod:self.tokenRequestHTTPMethod];
444445
[authConnection cancel]; // not needed, but looks more clean to me :)
445446

446447
NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithObjectsAndKeys:

0 commit comments

Comments
 (0)