From b5ebf008a81f8ce5538314a04b6a2ea376b19568 Mon Sep 17 00:00:00 2001 From: Aleksandr Dodatko Date: Fri, 10 Apr 2015 17:56:32 +0300 Subject: [PATCH] [refresh] Updating access token and posting notification on token refresh --- Sources/OAuth2Client/NXOAuth2AccountStore.m | 27 ++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/Sources/OAuth2Client/NXOAuth2AccountStore.m b/Sources/OAuth2Client/NXOAuth2AccountStore.m index 64df5be9..d28ca795 100644 --- a/Sources/OAuth2Client/NXOAuth2AccountStore.m +++ b/Sources/OAuth2Client/NXOAuth2AccountStore.m @@ -485,7 +485,7 @@ - (void)oauthClientNeedsAuthentication:(NXOAuth2Client *)client; #endif } -- (void)oauthClientDidGetAccessToken:(NXOAuth2Client *)client; +- (void)oauthClientDidGetAccessToken:(NXOAuth2Client *)client { NSString *accountType; @synchronized (self.pendingOAuthClients) { @@ -498,6 +498,31 @@ - (void)oauthClientDidGetAccessToken:(NXOAuth2Client *)client; [self addAccount:account]; } +- (void)oauthClientDidRefreshAccessToken:(NXOAuth2Client *)client +{ + NXOAuth2Account* foundAccount = nil; + + @synchronized (self.accountsDict) + { + for (NXOAuth2Account* account in self.accounts) + { + if (account.oauthClient == client) + { + foundAccount = account; + break; + } + } + } + + foundAccount.accessToken = client.accessToken; + NSDictionary *userInfo = [NSDictionary dictionaryWithObject: foundAccount + forKey: NXOAuth2AccountStoreNewAccountUserInfoKey]; + + [[NSNotificationCenter defaultCenter] postNotificationName:NXOAuth2AccountStoreAccountsDidChangeNotification + object:self + userInfo:userInfo]; +} + - (void)addAccount:(NXOAuth2Account *)account; { @synchronized (self.accountsDict) {