I have an issue with signing out from LinkedIn. I want to user see the LinkedIn sing in form with user name and password after performing signout method.
SingIn method:
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 method:
- (void) logout{
[GTMOAuthViewControllerTouch removeParamsFromKeychainForName:#"AppServiceName"];
}
But, the next time I singin, OAuth misses step there I need to enter LinkedIn credentials.
The App requests login and password only if it is deleted and installed again.
despite existens of [GTMOAuth clearBrowserCookies] method.
I manually remove all cookies with "linkedin" in domain in the singout method
NSHTTPCookieStorage *cookieStorage;
cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSArray *cookies = [cookieStorage cookies];
for (NSHTTPCookie *cookie in cookies) {
if ([cookie.domain rangeOfString:#"linkedin"].location != NSNotFound) {
[cookieStorage deleteCookie:cookie];
}
}
In Swift 3, Use the following code:
// 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)
}
}
}
Related
The problem is that Facebook use Safari when logged in, so when I try logout from my app it does keep credentials and cookies of Safari.
In other words, the only way to logout correctly is to open Safari and logout from Facebook.
My question is, is there any work around this way?
FBSDKLoginManager *loginManager = [FBSDKLoginManager new];
[loginManager logOut];
I also tried:
[FBSDKAccessToken setCurrentAccessToken:nil];
[FBSDKProfile setCurrentProfile:nil];
Although they are being called inside the logout method :(
Finally I tried removing cookies
NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSArray* facebookCookies = [cookies cookiesForURL:
[NSURL URLWithString:#"http://login.facebook.com"]];
for (NSHTTPCookie* cookie in facebookCookies) {
[cookies deleteCookie:cookie];
}
No luck at all!
I am using Fabric SDK for Twitter login into my app.
I want to remove session and cookie of Twitter from my iOS App. Because I am logging 1st time successfully from Twitter using this SDK. But if user wants to login from other credentials using Twitter into my app, then its not possible without clear session.
For clear session of Twitter, I am using following Code. But its not working.
[[Twitter sharedInstance]logOut];
[[Twitter sharedInstance]logOutGuest];
NSHTTPCookieStorage *cookieList = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (NSHTTPCookie *x in cookieList.cookies)
{
if ([[x valueForKey:#"domain"] isEqualToString:#".twitter.com"])
{
[cookieList deleteCookie:x];
}
}
Look forward to hearing your responses!
Try adding this to remove cookies
let cookie = NSHTTPCookie.self
let cookieStorage = NSHTTPCookieStorage.sharedHTTPCookieStorage()
for cookie in cookieStorage.cookies!
{
cookieStorage.deleteCookie(cookie)
}
In Objective-C
NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (NSHTTPCookie *httpCookie in cookieStorage.cookies)
{
if ([[httpCookie valueForKey:#"domain"] isEqualToString:#".twitter.com"])
{
[cookieStorage deleteCookie:httpCookie];
}
}
Did you use breakpoints in order to know if it is entering inside de if condition?
Btw, you have to change the code, you can't delete an object from the array while you are enumerating it. Maybe you can use another variable to persist the cookie when you find it and remove it out of the forin loop
// EDIT
NSHTTPCookieStorage *cookieList = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSMutableArray *cookies = [[NSMutableArray alloc] init];
for (NSHTTPCookie *x in cookieList.cookies)
{
if ([[x valueForKey:#"domain"] isEqualToString:#".twitter.com"])
{
[cookies addObject:x];
}
}
if (cookies.count > 0) {
for (NSHTTPCookie *cookie in cookies) {
[cookieList deleteCookie:cookie];
}
}
I created an array because I don't know how many cookies persist from twitter
Shared Instance Logout does not work. I know this is a big problem for developers. Does anyone have a solution? Thanks
I ran into this issue about 3 months ago and have just now found a solution to this. Apparently clearing cookies does in fact get rid of Twitter's stored information for previously logged in users. The code below is working for me:
!WARNING! Make sure when you first log in that you Disallow Twitter from accessing your accounts on the device. This causes Twitter to force login the user each time instead of looking straight at your Twitter account saved to your device. Hope this helps!
- (IBAction)twitterLogout:(id)sender {
[[Twitter sharedInstance] logOut];
[self.view insertSubview:_logoutTwitter atIndex:16];
NSHTTPCookie *cookie;
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [storage cookies])
{
NSString* domainName = [cookie domain];
NSRange domainRange = [domainName rangeOfString:#"Twitter"];
if(domainRange.length > 0)
{
[storage deleteCookie:cookie];
}
}
NSURL *url = [NSURL URLWithString:#"https://api.twitter.com"];
NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:url];
for (NSHTTPCookie *cookie in cookies)
{
[[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
}
}
I have read through the forums and suggestions about how to logout of Twitter in Xcode for IOS using Fabric, but I can't get the logOut method to call and logout the user from the current session. Here is my current code for the login view controller:
- (IBAction)TESTT:(id)sender {
[[Twitter sharedInstance] logInWithCompletion:^
(TWTRSession *session, NSError *error) {
if (session != nil) {
NSLog(#"signed in as %#", [session userName]);
} else {
NSLog(#"error: %#", [error localizedDescription]);
}
}];
}
- (IBAction)LOGOUT:(id)sender {
[self logOut];
}
- (void)logOut{
[[Twitter sharedInstance] logOut];
}
I have imported and have the login functionality working well from the Fabric tutorial.
I just can't get the button that I made which is using the LOGOUT action to logout the user from the current Twitter session. I have even tried to clear the cookies to see if that could wipe the Twitter session from the memory and reset it - but nothing. If anyone could help me out I would really appreciate it - thanks!
FYI: PLEASE do not suggest only [[Twitter sharedInstance] logOut]; . This method does not do what I am asking by itself. If someone can tell me how to successfully logout using this method along with the rest of the procedure that would be fine.
After a long extensive series of methods, clearing of cookies, data, almost everything you could think of, I discovered it is actually quite simple.
The easiest way to sign out and clear the previous user session is as follows:
Go to settings
Go to your Twitter and Disallow Twitter access to your app (it should appear here)
Go back to the app and call the following method:
- (void)twitterLogout:(id)sender {
NSUserDefaults *twitterSession = [NSUserDefaults standardUserDefaults];
[twitterSession setObject:0 forKey:#"TwitterSession"];
[twitterSession synchronize];
NSLog(#"Twitter session = %#", twitterSession);
[[Twitter sharedInstance] logOut];
[self.view insertSubview:_logoutTwitter atIndex:16];
NSHTTPCookie *cookie;
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [storage cookies])
{
NSString* domainName = [cookie domain];
NSRange domainRange = [domainName rangeOfString:#"Twitter"];
if(domainRange.length > 0)
{
[storage deleteCookie:cookie];
}
}
NSURL *url = [NSURL URLWithString:#"https://api.twitter.com"];
NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:url];
for (NSHTTPCookie *cookie in cookies)
{
[[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
}
}
There is quite a lot in this method, and to be honest some of it is probably extraneous and not even needed, but anyone who needs this can mess around with what should and shouldn't stay. Either way hopefully this helps people - it certainly helped me!
You can use this simple code for Swift 3:
let store = Twitter.sharedInstance().sessionStore
if let userID = store.session()?.userID {
store.logOutUserID(userID)
}
We have got sruck in the iOS facebook login logout issue. When I login to facebook using my application it will prompt for user permission with 'login' and 'cancel' button. But this screen appears only on the very first time. ie Once we logged in using safari or the app and even if we logged out from facebook , application the screen prompting for user permission displays only an 'ok' button. It doesnt allow to sign in as a different user. Why the screen with 'login' and 'cancel' button not displaying each time the application launches? I tried by deleting cookies and removing NSUserDefaults but no luck.
The problem is after logout, I am unable to login to the facebook as another user. It still shows as the same user.
I am calling the below logout function in sdk
(void)logout:(id<FBSessionDelegate>)delegate {
self.sessionDelegate = delegate;
[_accessToken release];
_accessToken = nil;
[_expirationDate release];
_expirationDate = nil;
NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSArray* facebookCookies = [cookies cookiesForURL:
[NSURL URLWithString:#"http://login.facebook.com"]];
for (NSHTTPCookie* cookie in facebookCookies) {
[cookies deleteCookie:cookie];
}
if ([self.sessionDelegate respondsToSelector:#selector(fbDidLogout)]) {
[_sessionDelegate fbDidLogout];
}
}
Also in fbDidLogout delegate function I removed all NSUserDefaults objects
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:#"FBAccessTokenKey"]) {
[defaults removeObjectForKey:#"FBAccessTokenKey"];
[defaults removeObjectForKey:#"FBExpirationDateKey"];
[defaults synchronize];
}
regrds
Shihab
You can clear the session as well as clearing the cookies with the following code:
FBSession* session = [FBSession activeSession];
[session closeAndClearTokenInformation];
[session close];
[FBSession setActiveSession:nil];
NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSArray* facebookCookies = [cookies cookiesForURL:[NSURL URLWithString:#"https://facebook.com/"]];
for (NSHTTPCookie* cookie in facebookCookies) {
[cookies deleteCookie:cookie];
}
FBSession openWithBehavior:completionHandler: can be used..
FBSession *fbSession = [[FBSession alloc] initWithPermissions:[NSArray arrayWithObjects:#"email",#"publish_actions",#"publish_stream", nil]];
[fbSession openWithBehavior:FBSessionLoginBehaviorForcingWebView completionHandler:^(FBSession *session,FBSessionState state, NSError *error){
[FBSession setActiveSession:fbSession]; // Retain the Active Session.
}];
For Logging out, Ans by Ellen S.. worked fine for iOS .
I modified fbDidLogout method and it worked, here is the code:
-(void) fbDidLogout
{
NSLog(#"Logged out of facebook");
NSHTTPCookie *cookie;
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [storage cookies])
{
NSString* domainName = [cookie domain];
NSRange domainRange = [domainName rangeOfString:#"facebook"];
if(domainRange.length > 0)
{
[storage deleteCookie:cookie];
}
}
}//End of Method
The method successfully logs out the user.
Hope this will help!
I just figure it out I got in the settings of my iPhone and got to privacy chose the Facebook tab and turn off where it says Applications that have requested access to you Facebook account will appear here. It works!!!
When login to set to loginBehavior, so when you exit, with the other account login, won't appear only authorized, without the login screen login.loginBehavior =FBSDKLoginBehaviorWeb; i use facebook 4.11,it's work