Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oauth header upgrade #210

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Sources/OAuth2Client/NXOAuth2Account.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,22 @@ - (NXOAuth2Client *)oauthClient;

NSString *clientID = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationClientID];
NSString *clientSecret = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationSecret];
NSString *grantType = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationGrantType];
NSURL *authorizeURL = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationAuthorizeURL];
NSURL *tokenURL = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationTokenURL];
NSString *tokenType = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationTokenType];
NSDictionary *additionalQueryParams = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationAdditionalAuthenticationParameters];

NSDictionary *headerParameters = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationHeaderParameters];

oauthClient = [[NXOAuth2Client alloc] initWithClientID:clientID
clientSecret:clientSecret
grantType:grantType
authorizeURL:authorizeURL
tokenURL:tokenURL
accessToken:self.accessToken
tokenType:tokenType
persistent:NO
headerParameters:headerParameters
delegate:self];
if (additionalQueryParams) {
oauthClient.additionalAuthenticationParameters = additionalQueryParams;
Expand Down
11 changes: 9 additions & 2 deletions Sources/OAuth2Client/NXOAuth2AccountStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,22 @@ extern NSString * const NXOAuth2AccountStoreNewAccountUserInfoKey;

extern NSString * const kNXOAuth2AccountStoreConfigurationClientID;
extern NSString * const kNXOAuth2AccountStoreConfigurationSecret;
extern NSString * const kNXOAuth2AccountStoreConfigurationGrantType;
extern NSString * const kNXOAuth2AccountStoreConfigurationAuthorizeURL;
extern NSString * const kNXOAuth2AccountStoreConfigurationTokenURL;
extern NSString * const kNXOAuth2AccountStoreConfigurationRedirectURL;
extern NSString * const kNXOAuth2AccountStoreConfigurationScope;
extern NSString * const kNXOAuth2AccountStoreConfigurationTokenType;


/*
/*
* Requires a NSDictionary as a value.
* They are passed onto the authentication request as additional query parameters.
* The dictionary may not contain the keys "grant_type", "client_id", "client_secret",
* "username", "password", "redirect_uri", "code", "assertion_type" and "assertion" are not allowed.
*/
extern NSString * const kNXOAuth2AccountStoreConfigurationAdditionalAuthenticationParameters;

extern NSString * const kNXOAuth2AccountStoreConfigurationHeaderParameters;

#pragma mark Account Type

Expand Down Expand Up @@ -81,25 +82,31 @@ typedef void(^NXOAuth2PreparedAuthorizationURLHandler)(NSURL *preparedURL);

- (void)setClientID:(NSString *)aClientID
secret:(NSString *)aSecret
grantType:(NSString *)aGrantType
authorizationURL:(NSURL *)anAuthorizationURL
tokenURL:(NSURL *)aTokenURL
redirectURL:(NSURL *)aRedirectURL
headerParameters:(NSDictionary *) someHeaderParameters
forAccountType:(NSString *)anAccountType;

- (void)setClientID:(NSString *)aClientID
secret:(NSString *)aSecret
grantType:(NSString *)aGrantType
scope:(NSSet *)theScope
authorizationURL:(NSURL *)anAuthorizationURL
tokenURL:(NSURL *)aTokenURL
redirectURL:(NSURL *)aRedirectURL
headerParameters:(NSDictionary *) someHeaderParameters
forAccountType:(NSString *)anAccountType;

- (void)setClientID:(NSString *)aClientID
secret:(NSString *)aSecret
grantType:(NSString *)aGrantType
scope:(NSSet *)theScope
authorizationURL:(NSURL *)anAuthorizationURL
tokenURL:(NSURL *)aTokenURL
redirectURL:(NSURL *)aRedirectURL
headerParameters:(NSDictionary *) someHeaderParameters
tokenType:(NSString *)aTokenType
forAccountType:(NSString *)anAccountType;

Expand Down
34 changes: 26 additions & 8 deletions Sources/OAuth2Client/NXOAuth2AccountStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@

NSString * const kNXOAuth2AccountStoreConfigurationClientID = @"kNXOAuth2AccountStoreConfigurationClientID";
NSString * const kNXOAuth2AccountStoreConfigurationSecret = @"kNXOAuth2AccountStoreConfigurationSecret";
NSString * const kNXOAuth2AccountStoreConfigurationGrantType = @"kNXOAuth2AccountStoreConfigurationGrantType";
NSString * const kNXOAuth2AccountStoreConfigurationAuthorizeURL = @"kNXOAuth2AccountStoreConfigurationAuthorizeURL";
NSString * const kNXOAuth2AccountStoreConfigurationTokenURL = @"kNXOAuth2AccountStoreConfigurationTokenURL";
NSString * const kNXOAuth2AccountStoreConfigurationRedirectURL = @"kNXOAuth2AccountStoreConfigurationRedirectURL";
NSString * const kNXOAuth2AccountStoreConfigurationScope = @"kNXOAuth2AccountStoreConfigurationScope";
NSString * const kNXOAuth2AccountStoreConfigurationTokenType = @"kNXOAuth2AccountStoreConfigurationTokenType";
NSString * const kNXOAuth2AccountStoreConfigurationAdditionalAuthenticationParameters = @"kNXOAuth2AccountStoreConfigurationAdditionalAuthenticationParameters";
NSString * const kNXOAuth2AccountStoreConfigurationHeaderParameters = @"kNXOAuth2AccountStoreConfigurationHeaderParameters";

#pragma mark Account Type

Expand Down Expand Up @@ -226,55 +228,67 @@ - (void)removeAccount:(NXOAuth2Account *)account;

- (void)setClientID:(NSString *)aClientID
secret:(NSString *)aSecret
grantType:(NSString *)aGrantType
authorizationURL:(NSURL *)anAuthorizationURL
tokenURL:(NSURL *)aTokenURL
redirectURL:(NSURL *)aRedirectURL
headerParameters:(NSDictionary *) someHeaderParameters
forAccountType:(NSString *)anAccountType;
{
[self setConfiguration:[NSDictionary dictionaryWithObjectsAndKeys:
aClientID, kNXOAuth2AccountStoreConfigurationClientID,
aSecret, kNXOAuth2AccountStoreConfigurationSecret,
aGrantType, kNXOAuth2AccountStoreConfigurationGrantType,
anAuthorizationURL, kNXOAuth2AccountStoreConfigurationAuthorizeURL,
aTokenURL, kNXOAuth2AccountStoreConfigurationTokenURL,
aRedirectURL, kNXOAuth2AccountStoreConfigurationRedirectURL, nil]
aRedirectURL, kNXOAuth2AccountStoreConfigurationRedirectURL,
someHeaderParameters, kNXOAuth2AccountStoreConfigurationHeaderParameters, nil]
forAccountType:anAccountType];
}

- (void)setClientID:(NSString *)aClientID
secret:(NSString *)aSecret
grantType:(NSString *)aGrantType
scope:(NSSet *)theScope
authorizationURL:(NSURL *)anAuthorizationURL
tokenURL:(NSURL *)aTokenURL
redirectURL:(NSURL *)aRedirectURL
headerParameters:(NSDictionary *) someHeaderParameters
forAccountType:(NSString *)anAccountType;
{
[self setConfiguration:[NSDictionary dictionaryWithObjectsAndKeys:
aClientID, kNXOAuth2AccountStoreConfigurationClientID,
aSecret, kNXOAuth2AccountStoreConfigurationSecret,
aGrantType, kNXOAuth2AccountStoreConfigurationGrantType,
theScope, kNXOAuth2AccountStoreConfigurationScope,
anAuthorizationURL, kNXOAuth2AccountStoreConfigurationAuthorizeURL,
aTokenURL, kNXOAuth2AccountStoreConfigurationTokenURL,
aRedirectURL, kNXOAuth2AccountStoreConfigurationRedirectURL, nil]
aRedirectURL, kNXOAuth2AccountStoreConfigurationRedirectURL,
someHeaderParameters, kNXOAuth2AccountStoreConfigurationHeaderParameters, nil]
forAccountType:anAccountType];
}

- (void)setClientID:(NSString *)aClientID
secret:(NSString *)aSecret
grantType:(NSString *)aGrantType
scope:(NSSet *)theScope
authorizationURL:(NSURL *)anAuthorizationURL
tokenURL:(NSURL *)aTokenURL
redirectURL:(NSURL *)aRedirectURL
headerParameters:(NSDictionary *) someHeaderParameters
tokenType:(NSString *)aTokenType
forAccountType:(NSString *)anAccountType;
{
[self setConfiguration:[NSDictionary dictionaryWithObjectsAndKeys:
aClientID, kNXOAuth2AccountStoreConfigurationClientID,
aSecret, kNXOAuth2AccountStoreConfigurationSecret,
aGrantType, kNXOAuth2AccountStoreConfigurationGrantType,
theScope, kNXOAuth2AccountStoreConfigurationScope,
anAuthorizationURL, kNXOAuth2AccountStoreConfigurationAuthorizeURL,
aTokenURL, kNXOAuth2AccountStoreConfigurationTokenURL,
aTokenType, kNXOAuth2AccountStoreConfigurationTokenType,
aRedirectURL, kNXOAuth2AccountStoreConfigurationRedirectURL, nil]
aRedirectURL, kNXOAuth2AccountStoreConfigurationRedirectURL,
someHeaderParameters, kNXOAuth2AccountStoreConfigurationHeaderParameters, nil]
forAccountType:anAccountType];
}

Expand Down Expand Up @@ -391,19 +405,23 @@ - (NXOAuth2Client *)pendingOAuthClientForAccountType:(NSString *)accountType;

NSString *clientID = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationClientID];
NSString *clientSecret = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationSecret];
NSString *grantType = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationGrantType];
NSSet *scope = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationScope];
NSURL *authorizeURL = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationAuthorizeURL];
NSURL *tokenURL = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationTokenURL];
NSString *tokenType = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationTokenType];
NSDictionary *additionalAuthenticationParameters = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationAdditionalAuthenticationParameters];
NSDictionary *headerParameters = [configuration objectForKey:kNXOAuth2AccountStoreConfigurationHeaderParameters];

client = [[NXOAuth2Client alloc] initWithClientID:clientID
clientSecret:clientSecret
grantType:grantType
authorizeURL:authorizeURL
tokenURL:tokenURL
accessToken:nil
tokenType:tokenType
persistent:YES
headerParameters:headerParameters
delegate:self];

client.persistent = NO;
Expand Down Expand Up @@ -455,9 +473,9 @@ - (void)oauthClientNeedsAuthentication:(NXOAuth2Client *)client;
NSURL *preparedURL = [client authorizationURLWithRedirectURL:redirectURL];

#if TARGET_OS_IPHONE
[[UIApplication sharedApplication] openURL:preparedURL];
[[UIApplication sharedApplication] openURL:preparedURL];
#else
[[NSWorkspace sharedWorkspace] openURL:preparedURL];
[[NSWorkspace sharedWorkspace] openURL:preparedURL];
#endif
}

Expand Down Expand Up @@ -596,7 +614,7 @@ + (NSDictionary *)accountsFromDefaultKeychain;
+ (void)storeAccountsInDefaultKeychain:(NSDictionary *)accounts;
{
[self removeFromDefaultKeychain];

NSString *serviceName = [self keychainServiceName];

NSData *data = [NSKeyedArchiver archivedDataWithRootObject:accounts];
Expand All @@ -619,7 +637,7 @@ + (void)removeFromDefaultKeychain;
nil];
OSStatus __attribute__((unused)) err = SecItemDelete((__bridge CFDictionaryRef)query);
NSAssert1((err == noErr || err == errSecItemNotFound), @"Error while deleting token from keychain: %ld", err);

}

#else
Expand Down Expand Up @@ -675,7 +693,7 @@ + (NSDictionary *)accountsFromDefaultKeychain;
+ (void)storeAccountsInDefaultKeychain:(NSDictionary *)accounts;
{
[self removeFromDefaultKeychain];

NSString *serviceName = [self keychainServiceName];

NSData *data = [NSKeyedArchiver archivedDataWithRootObject:accounts];
Expand Down
11 changes: 10 additions & 1 deletion Sources/OAuth2Client/NXOAuth2Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ extern NSString * const NXOAuth2ClientConnectionContextTokenRefresh;
@protected
BOOL authenticating;
BOOL persistent;

NSString *clientId;
NSString *clientSecret;
NSString *grantType;
NSDictionary *headerParameters;

NSSet *desiredScope;
NSString *userAgent;
Expand All @@ -62,8 +64,11 @@ extern NSString * const NXOAuth2ClientConnectionContextTokenRefresh;

@property (nonatomic, copy, readonly) NSString *clientId;
@property (nonatomic, copy, readonly) NSString *clientSecret;
@property (nonatomic, copy, readonly) NSString *grantType;
@property (nonatomic, copy, readonly) NSString *tokenType;
@property (nonatomic, strong, readwrite) NSDictionary *additionalAuthenticationParameters;
@property (nonatomic, strong, readwrite) NSDictionary *headerParameters;


@property (nonatomic, copy) NSSet *desiredScope;
@property (nonatomic, copy) NSString *userAgent;
Expand All @@ -84,12 +89,14 @@ extern NSString * const NXOAuth2ClientConnectionContextTokenRefresh;
*/
- (id)initWithClientID:(NSString *)clientId
clientSecret:(NSString *)clientSecret
grantType:(NSString *)aGrantType
authorizeURL:(NSURL *)authorizeURL
tokenURL:(NSURL *)tokenURL
delegate:(NSObject<NXOAuth2ClientDelegate> *)delegate;

- (id)initWithClientID:(NSString *)clientId
clientSecret:(NSString *)clientSecret
grantType:(NSString *)aGrantType
authorizeURL:(NSURL *)authorizeURL
tokenURL:(NSURL *)tokenURL
accessToken:(NXOAuth2AccessToken *)accessToken
Expand All @@ -98,11 +105,13 @@ extern NSString * const NXOAuth2ClientConnectionContextTokenRefresh;

- (id)initWithClientID:(NSString *)clientId
clientSecret:(NSString *)clientSecret
grantType:(NSString *)aGrantType
authorizeURL:(NSURL *)authorizeURL
tokenURL:(NSURL *)tokenURL
accessToken:(NXOAuth2AccessToken *)accessToken
tokenType:(NSString *)tokenType
persistent:(BOOL)shouldPersist
headerParameters:(NSDictionary*)someheaderParameters
delegate:(NSObject<NXOAuth2ClientDelegate> *)delegate;

- (BOOL)openRedirectURL:(NSURL *)URL;
Expand Down
Loading