Skip to content

Commit b5ebf00

Browse files
Aleksandr Dodatkowireframe
authored andcommitted
[refresh] Updating access token and posting notification on token refresh
1 parent 5fe6147 commit b5ebf00

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

Sources/OAuth2Client/NXOAuth2AccountStore.m

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ - (void)oauthClientNeedsAuthentication:(NXOAuth2Client *)client;
485485
#endif
486486
}
487487

488-
- (void)oauthClientDidGetAccessToken:(NXOAuth2Client *)client;
488+
- (void)oauthClientDidGetAccessToken:(NXOAuth2Client *)client
489489
{
490490
NSString *accountType;
491491
@synchronized (self.pendingOAuthClients) {
@@ -498,6 +498,31 @@ - (void)oauthClientDidGetAccessToken:(NXOAuth2Client *)client;
498498
[self addAccount:account];
499499
}
500500

501+
- (void)oauthClientDidRefreshAccessToken:(NXOAuth2Client *)client
502+
{
503+
NXOAuth2Account* foundAccount = nil;
504+
505+
@synchronized (self.accountsDict)
506+
{
507+
for (NXOAuth2Account* account in self.accounts)
508+
{
509+
if (account.oauthClient == client)
510+
{
511+
foundAccount = account;
512+
break;
513+
}
514+
}
515+
}
516+
517+
foundAccount.accessToken = client.accessToken;
518+
NSDictionary *userInfo = [NSDictionary dictionaryWithObject: foundAccount
519+
forKey: NXOAuth2AccountStoreNewAccountUserInfoKey];
520+
521+
[[NSNotificationCenter defaultCenter] postNotificationName:NXOAuth2AccountStoreAccountsDidChangeNotification
522+
object:self
523+
userInfo:userInfo];
524+
}
525+
501526
- (void)addAccount:(NXOAuth2Account *)account;
502527
{
503528
@synchronized (self.accountsDict) {

0 commit comments

Comments
 (0)