Prompt the user to authenticate again when using the refresh_token gives an error. Also, show the error to the user. GoogleOAuth2 GoogleOAuth2_bookmark
authorThijs Alkemade <me@thijsalkema.de>
Wed, 01 Apr 2015 21:07:40 +0200
branchGoogleOAuth2
changeset 5914 c4923ddd82bf
parent 5912 1ff2b33ca0c1
child 5915 c71963566b9b
child 5917 4a7c414c0b2d
Prompt the user to authenticate again when using the refresh_token gives an error. Also, show the error to the user.
Plugins/Purple Service/AIPurpleGTalkAccount.m
--- a/Plugins/Purple Service/AIPurpleGTalkAccount.m	Wed Apr 01 20:30:40 2015 +0200
+++ b/Plugins/Purple Service/AIPurpleGTalkAccount.m	Wed Apr 01 21:07:40 2015 +0200
@@ -221,6 +221,17 @@
 	
 	AILogWithSignature(@"%@", responseDict);
 	
+	if ([responseDict objectForKey:@"error"]) {
+		// Delete the refresh token, so we don't use it again.
+		[[AIKeychain defaultKeychain_error:NULL] deleteGenericPasswordForService:self.service.serviceID
+																		 account:self.UID
+																		   error:NULL];
+		
+		[self setLastDisconnectionError:[NSString stringWithFormat:AILocalizedString(@"Retrieving OAuth token failed: %@", nil), [responseDict objectForKey:@"error_description"]]];
+		[self serverReportedInvalidPassword];
+		return;
+	}
+	
 	if (!self.UID.length) {
 		NSString *jsonWebToken = [responseDict objectForKey:@"id_token"];
 		
@@ -291,7 +302,6 @@
 
 -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
 	[self setLastDisconnectionError:[NSString stringWithFormat:AILocalizedString(@"OAuth authentication failed: %@", nil), error.description]];
-	[self setValue:[NSNumber numberWithBool:YES] forProperty:@"isDisconnecting" notify:NotifyNow];
 }
 
 - (void)retrievePasswordThenConnect