Skip to content
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
38 changes: 30 additions & 8 deletions Sources/OAuth2Client/NXOAuth2AccountStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,13 @@ - (void)oauthClientDidRefreshAccessToken:(NXOAuth2Client *)client
}
}

foundAccount.accessToken = client.accessToken;
NSDictionary *userInfo = [NSDictionary dictionaryWithObject: foundAccount
forKey: NXOAuth2AccountStoreNewAccountUserInfoKey];
NSDictionary *userInfo = @{};

if (foundAccount)
{
foundAccount.accessToken = client.accessToken;
userInfo = @{ NXOAuth2AccountStoreNewAccountUserInfoKey : foundAccount};
}

[[NSNotificationCenter defaultCenter] postNotificationName:NXOAuth2AccountStoreAccountsDidChangeNotification
object:self
Expand Down Expand Up @@ -589,13 +593,24 @@ - (void)oauthClient:(NXOAuth2Client *)client didFailToGetAccessTokenWithError:(N
NSString *accountType;
@synchronized (self.pendingOAuthClients) {
accountType = [self accountTypeOfPendingOAuthClient:client];
[self.pendingOAuthClients removeObjectForKey:accountType];

if (nil != accountType)
{
[self.pendingOAuthClients removeObjectForKey:accountType];
}
}

NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
accountType, kNXOAuth2AccountStoreAccountType,
error, NXOAuth2AccountStoreErrorKey, nil];

NSDictionary *userInfo = nil;
if (nil != accountType)
{
userInfo = @{kNXOAuth2AccountStoreAccountType: accountType, NXOAuth2AccountStoreErrorKey : error};
}
else
{
userInfo = @{NXOAuth2AccountStoreErrorKey : error};
}


[[NSNotificationCenter defaultCenter] postNotificationName:NXOAuth2AccountStoreDidFailToRequestAccessNotification
object:self
userInfo:userInfo];
Expand Down Expand Up @@ -640,6 +655,13 @@ - (void)accountDidChangeAccessToken:(NSNotification *)aNotification;
// Save all accounts in the default keychain.
[self storeAccountsInDefaultKeychain:self.accountsDict withAccessGroup:self.keychainAccessGroup];
}

NXOAuth2Account* notificationSender = aNotification.object;

NSDictionary* userInfo = @{ NXOAuth2AccountStoreNewAccountUserInfoKey : notificationSender};
[[NSNotificationCenter defaultCenter] postNotificationName: NXOAuth2AccountStoreAccountsDidChangeNotification
object: self
userInfo: userInfo];
}

- (void)accountDidLoseAccessToken:(NSNotification *)aNotification;
Expand Down
14 changes: 14 additions & 0 deletions Sources/OAuth2Client/NXOAuth2Connection.m
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,20 @@ - (NSURLConnection *)createConnection;

oauthAuthorizationHeader = [NSString stringWithFormat:@"%@ %@", tokenType, client.accessToken.accessToken];
}
else if (isRefreshToken)
{
NSString* nonEncodedIdAndSecret =
[NSString stringWithFormat:
@"%@:%@",
requestParameters[@"client_id"],
requestParameters[@"client_secret"] ];


NSData* nonEncodedIdAndSecretBinary = [nonEncodedIdAndSecret dataUsingEncoding: NSUTF8StringEncoding];

NSString* base64IdAndSecret = [nonEncodedIdAndSecretBinary base64EncodedStringWithOptions: (NSDataBase64EncodingOptions)0];
oauthAuthorizationHeader = [NSString stringWithFormat: @"Basic %@", base64IdAndSecret];
}

NSMutableURLRequest *startRequest = [request mutableCopy];
[self applyParameters:requestParameters onRequest:startRequest];
Expand Down