Skip to content

Commit 183a40b

Browse files
author
toto
committed
Merge pull request #52 from squarefrog/develop
Created authenticate with client credentials method, for account creation
2 parents 2ca6f87 + 4030dc2 commit 183a40b

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

Sources/OAuth2Client/NXOAuth2AccountStore.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ typedef void(^NXOAuth2PreparedAuthorizationURLHandler)(NSURL *preparedURL);
123123
- (void)requestAccessToAccountWithType:(NSString *)accountType withPreparedAuthorizationURLHandler:(NXOAuth2PreparedAuthorizationURLHandler)aPreparedAuthorizationURLHandler;
124124
- (void)requestAccessToAccountWithType:(NSString *)accountType username:(NSString *)username password:(NSString *)password;
125125
- (void)requestAccessToAccountWithType:(NSString *)accountType assertionType:(NSURL *)assertionType assertion:(NSString *)assertion;
126+
- (void)requestClientCredentialsAccessWithType:(NSString *)accountType;
126127
- (void)removeAccount:(NXOAuth2Account *)account;
127128

128129

Sources/OAuth2Client/NXOAuth2AccountStore.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@ - (void)requestAccessToAccountWithType:(NSString *)accountType assertionType:(NS
205205
[client authenticateWithAssertionType:assertionType assertion:assertion];
206206
}
207207

208+
- (void)requestClientCredentialsAccessWithType:(NSString *)accountType;
209+
{
210+
NXOAuth2Client *client = [self pendingOAuthClientForAccountType:accountType];
211+
[client authenticateWithClientCredentials];
212+
}
213+
208214
- (void)removeAccount:(NXOAuth2Account *)account;
209215
{
210216
if (account) {

Sources/OAuth2Client/NXOAuth2Client.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ extern NSString * const NXOAuth2ClientConnectionContextTokenRefresh;
122122
/*!
123123
* Authenticate with username & password (User Credentials Flow)
124124
*/
125+
- (void)authenticateWithClientCredentials;
125126
- (void)authenticateWithUsername:(NSString *)username password:(NSString *)password;
126127

127128
/*!

Sources/OAuth2Client/NXOAuth2Client.m

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,31 @@ - (void)requestTokenWithAuthGrant:(NSString *)authGrant redirectURL:(NSURL *)red
333333
authConnection.context = NXOAuth2ClientConnectionContextTokenRequest;
334334
}
335335

336+
// Client Credential Flow
337+
- (void)authenticateWithClientCredentials;
338+
{
339+
NSAssert1(!authConnection, @"authConnection already running with: %@", authConnection);
340+
341+
NSMutableURLRequest *tokenRequest = [NSMutableURLRequest requestWithURL:tokenURL];
342+
[tokenRequest setHTTPMethod:@"POST"];
343+
[authConnection cancel]; // just to be sure
344+
345+
self.authenticating = YES;
346+
347+
NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithObjectsAndKeys:
348+
@"client_credentials", @"grant_type",
349+
clientId, @"client_id",
350+
clientSecret, @"client_secret",
351+
nil];
352+
if (self.desiredScope) {
353+
[parameters setObject:[[self.desiredScope allObjects] componentsJoinedByString:@" "] forKey:@"scope"];
354+
}
355+
authConnection = [[NXOAuth2Connection alloc] initWithRequest:tokenRequest
356+
requestParameters:parameters
357+
oauthClient:self
358+
delegate:self];
359+
authConnection.context = NXOAuth2ClientConnectionContextTokenRequest;
360+
}
336361

337362
// User Password Flow Only
338363
- (void)authenticateWithUsername:(NSString *)username password:(NSString *)password;

0 commit comments

Comments
 (0)