我从LinkedIn退出时遇到问题。我希望用户在执行注销方法后看到带有用户名和密码的LinkedIn唱歌。
SingIn方法:
NSURL *authorizeTokenURL = [NSURL URLWithString:@"https://www.linkedin.com/uas/oauth/authenticate"];
NSURL *accessTokenURL = [NSURL URLWithString:@"https://api.linkedin.com/uas/oauth/accessToken"];
GTMOAuthViewControllerTouch *authViewControllerTouch = [[GTMOAuthViewControllerTouch alloc] initWithScope:nil language:nil requestTokenURL:requestTokenURL authorizeTokenURL:authorizeTokenURL accessTokenURL:accessTokenURL authentication:authentication appServiceName:@"AppServiceName" delegate:self finishedSelector:@selector(linkedInAuthSelector:finishedWithAuth:error:)];
[authViewControllerTouch setBrowserCookiesURL:[NSURL URLWithString:@"https://api.linkedin.com/"]];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:authViewControllerTouch];
[self presentViewController:navigationController animated:YES completion:nil];
Singout方法:
- (void) logout{
[GTMOAuthViewControllerTouch removeParamsFromKeychainForName:@"AppServiceName"];
}
但是,下次我唱歌时,OAuth错过了那里,我需要输入LinkedIn凭据。
仅当应用程序被删除并重新安装时,应用程序才会请求登录名和密码。
答案 0 :(得分:1)
尽管存在[GTMOAuth2 clearBrowserCookies]方法。 我在singout方法中手动删除域中“linkedin”的所有cookie
NSHTTPCookieStorage *cookieStorage;
cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSArray *cookies = [cookieStorage cookies];
for (NSHTTPCookie *cookie in cookies) {
if ([cookie.domain rangeOfString:@"linkedin"].location != NSNotFound) {
[cookieStorage deleteCookie:cookie];
}
}
答案 1 :(得分:1)
在Swift 3中,使用以下代码:
// LinkedIn Cookie Purge
let cookieStorage: HTTPCookieStorage = HTTPCookieStorage.shared
if let cookies = cookieStorage.cookies {
for cookie in cookies {
if cookie.domain.contains("linkedin") {
cookieStorage.deleteCookie(cookie)
}
}
}