Skip to content

Commit dbfafcd

Browse files
committed
Merge branch 'feature/additionalQueryParams' into develop
Conflicts: Sources/OAuth2Client/NXOAuth2Client.m
2 parents 59373e8 + 2096152 commit dbfafcd

File tree

5 files changed

+61
-1
lines changed

5 files changed

+61
-1
lines changed

Sources/OAuth2Client/NXOAuth2Account.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ - (NXOAuth2Client *)oauthClient;
8181
NSURL *authorizeURL = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationAuthorizeURL];
8282
NSURL *tokenURL = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationTokenURL];
8383
NSString *tokenType = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationTokenType];
84-
84+
NSDictionary *additionalQueryParams = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationAdditionalAuthenticationParameters];
85+
8586
oauthClient = [[NXOAuth2Client alloc] initWithClientID:clientID
8687
clientSecret:clientSecret
8788
authorizeURL:authorizeURL
@@ -90,6 +91,10 @@ - (NXOAuth2Client *)oauthClient;
9091
tokenType:tokenType
9192
persistent:NO
9293
delegate:self];
94+
if (additionalQueryParams) {
95+
oauthClient.additionalAuthenticationParameters = additionalQueryParams;
96+
}
97+
9398
}
9499
}
95100
return oauthClient;

Sources/OAuth2Client/NXOAuth2AccountStore.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ extern NSString * const kNXOAuth2AccountStoreConfigurationScope;
3636
extern NSString * const kNXOAuth2AccountStoreConfigurationTokenType;
3737

3838

39+
/*
40+
* Requires a NSDictionary as a value.
41+
* They are passed onto the authentication request as additional query parameters.
42+
* The dictionary may not contain the keys "grant_type", "client_id", "client_secret",
43+
* "username", "password", "redirect_uri", "code", "assertion_type" and "assertion" are not allowed.
44+
*/
45+
extern NSString * const kNXOAuth2AccountStoreConfigurationAdditionalAuthenticationParameters;
46+
47+
3948
#pragma mark Account Type
4049

4150
extern NSString * const kNXOAuth2AccountStoreAccountType;

Sources/OAuth2Client/NXOAuth2AccountStore.m

Lines changed: 7 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 kNXOAuth2AccountStoreConfigurationAdditionalAuthenticationParameters = @"kNXOAuth2AccountStoreConfigurationAdditionalAuthenticationParameters";
4546

4647
#pragma mark Account Type
4748

@@ -388,6 +389,7 @@ - (NXOAuth2Client *)pendingOAuthClientForAccountType:(NSString *)accountType;
388389
NSURL *authorizeURL = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationAuthorizeURL];
389390
NSURL *tokenURL = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationTokenURL];
390391
NSString *tokenType = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationTokenType];
392+
NSDictionary *additionalAuthenticationParameters = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationAdditionalAuthenticationParameters];
391393

392394
client = [[NXOAuth2Client alloc] initWithClientID:clientID
393395
clientSecret:clientSecret
@@ -400,6 +402,11 @@ - (NXOAuth2Client *)pendingOAuthClientForAccountType:(NSString *)accountType;
400402

401403
client.persistent = NO;
402404

405+
if (additionalAuthenticationParameters != nil) {
406+
NSAssert([additionalAuthenticationParameters isKindOfClass:[NSDictionary class]], @"additionalAuthenticationParameters have to be a NSDictionary");
407+
client.additionalAuthenticationParameters = additionalAuthenticationParameters;
408+
}
409+
403410
if (scope != nil) {
404411
client.desiredScope = scope;
405412
}

Sources/OAuth2Client/NXOAuth2Client.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,15 @@ extern NSString * const NXOAuth2ClientConnectionContextTokenRefresh;
6363
@property (nonatomic, copy, readonly) NSString *clientId;
6464
@property (nonatomic, copy, readonly) NSString *clientSecret;
6565
@property (nonatomic, copy, readonly) NSString *tokenType;
66+
@property (nonatomic, strong, readwrite) NSDictionary *additionalAuthenticationParameters;
6667

6768
@property (nonatomic, copy) NSSet *desiredScope;
6869
@property (nonatomic, copy) NSString *userAgent;
6970

7071
@property (nonatomic, strong) NXOAuth2AccessToken *accessToken;
7172
@property (nonatomic, unsafe_unretained) NSObject<NXOAuth2ClientDelegate>* delegate;
7273

74+
7375
/*!
7476
* If set to NO, the access token is not stored any keychain, will be removed if it was.
7577
* Defaults to YES

Sources/OAuth2Client/NXOAuth2Client.m

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,30 @@ - (void)dealloc;
108108
@synthesize clientId, clientSecret, tokenType;
109109
@synthesize desiredScope, userAgent;
110110
@synthesize delegate, persistent, accessToken, authenticating;
111+
@synthesize additionalAuthenticationParameters;
112+
113+
- (void)setAdditionalAuthenticationParameters:(NSDictionary *)value;
114+
{
115+
if (value == additionalAuthenticationParameters) return;
116+
117+
NSArray *forbiddenKeys = @[ @"grant_type", @"client_id",
118+
@"client_secret",
119+
@"username", @"password",
120+
@"redirect_uri", @"code",
121+
@"assertion_type", @"assertion" ];
122+
123+
for (id key in value) {
124+
if ([forbiddenKeys containsObject:key]) {
125+
[[NSException exceptionWithName:NSInvalidArgumentException
126+
reason:[NSString stringWithFormat:@"'%@' is not allowed as a key for additionalAuthenticationParameters", key]
127+
userInfo:nil] raise];
128+
}
129+
}
130+
131+
additionalAuthenticationParameters = value;
132+
133+
134+
}
111135

112136
- (void)setPersistent:(BOOL)shouldPersist;
113137
{
@@ -204,6 +228,10 @@ - (NSURL *)authorizationURLWithRedirectURL:(NSURL *)redirectURL;
204228
[redirectURL absoluteString], @"redirect_uri",
205229
nil];
206230

231+
if (self.additionalAuthenticationParameters) {
232+
[parameters addEntriesFromDictionary:self.additionalAuthenticationParameters];
233+
}
234+
207235
if (self.desiredScope.count > 0) {
208236
[parameters setObject:[[self.desiredScope allObjects] componentsJoinedByString:@" "] forKey:@"scope"];
209237
}
@@ -294,6 +322,10 @@ - (void)requestTokenWithAuthGrant:(NSString *)authGrant redirectURL:(NSURL *)red
294322
[parameters setObject:[[self.desiredScope allObjects] componentsJoinedByString:@" "] forKey:@"scope"];
295323
}
296324

325+
if (self.additionalAuthenticationParameters) {
326+
[parameters addEntriesFromDictionary:self.additionalAuthenticationParameters];
327+
}
328+
297329
authConnection = [[NXOAuth2Connection alloc] initWithRequest:tokenRequest
298330
requestParameters:parameters
299331
oauthClient:self
@@ -323,6 +355,11 @@ - (void)authenticateWithUsername:(NSString *)username password:(NSString *)passw
323355
if (self.desiredScope) {
324356
[parameters setObject:[[self.desiredScope allObjects] componentsJoinedByString:@" "] forKey:@"scope"];
325357
}
358+
359+
if (self.additionalAuthenticationParameters) {
360+
[parameters addEntriesFromDictionary:self.additionalAuthenticationParameters];
361+
}
362+
326363
authConnection = [[NXOAuth2Connection alloc] initWithRequest:tokenRequest
327364
requestParameters:parameters
328365
oauthClient:self

0 commit comments

Comments
 (0)