Reputation: 714
I'm using Google's guide to integrate Drive's functionalities in an app of my own, but I cannot find a way that allows me to log out of my google account from within the app.
Is there anything I can call to logout, or am I supposed to stay logged in until I uninstall the app?
Upvotes: 2
Views: 920
Reputation: 36620
This works for me with Swift 2.2:
GTMOAuth2ViewControllerTouch.removeAuthFromKeychainForName(kKeychainItemName)
Upvotes: 1
Reputation: 714
After doing some more attempts, I may have found the solution:
In viewDidLoad, the Drive API service is initialized this way (taken from the aforementioned guide):
// Initialize the Drive API service & load existing credentials from the keychain if available.
self.service = [[GTLServiceDrive alloc] init];
self.service.authorizer =
[GTMOAuth2ViewControllerTouch authForGoogleFromKeychainForName:kKeychainItemName
clientID:kClientID
clientSecret:nil];
So to logout, it should be enough to remove the authorization from the keychain:
[GTMOAuth2ViewControllerTouch removeAuthFromKeychainForName:kKeychainItemName];
I just tried this out and it seems to be working. After this call, if I try to get back in the View, I'm prompted again for my credentials.
Upvotes: 3
Reputation: 18888
I'd assume clearing the cookies would do it. For example:
NSHTTPCookie *cookie;
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [storage cookies]) {
[storage deleteCookie:cookie];
}
NSHTTPCookieStorage Class Reference
Upvotes: 1