How To Sign Out Using When Using Google+ Sign-In - oauth-2.0

Google documents there gapi.auth.signOut() method here: https://developers.google.com/+/web/signin/#sign-out
The catch is that it says you can only call that method after the signinCallback has fired. So far as I can tell, the only way to fire the signinCallback is to put a sign-in button on the page.
This works great on my sign-in page itself, but as soon as I've authenticated a user, there's no need to put the G+ sign-in button on subsequent pages. I just want to have a small 'log out' link in the corner that the user can click to sign-out.
I tried having my log-out link call gapi.auth.signOut() but it does nothing unless I am also showing a useless log-in button. How do I get this to work?

The button just has to be in the DOM, it doesn't have to be showing. What seems to work well is:
Create a hidden element and attach the gapi handler with gapi.signin.render
Wait for the immediate_failed error - display the button then
Otherwise, accept the signed in callback, and display the logout button
Then you'll get a callback every time, but only show the button when signed out.

Related

Twitter login page comes up even though user denies to give access to Twitter from App

When I am trying to login to my App in iOS 11 using Twitter, sometimes I am getting an alertview-style popup saying “ wants to open twitter”, with the options "cancel" and "open". If I tap on "open", it is the normal login flow for twitter.
However, if I tap on cancel, then what I want is for the whole login attempt to be cancelled. Instead, the app redirects me to the webview which opens twitter login page and again I need to cancel that dismiss the page saying “Error during login”. Could anyone able to simulate it?
Looks like it might be related to a known issue that Twitter is trying to fix? See https://twittercommunity.com/t/bug-twitter-kit-ios-3-0-4-login-sometimes-fails-to-redirect-back-to-host-app/89618/24

Facebook Login for iOS

I already have a Facebook Login Button, that works perfectly (upon pressing the button, I get to a login screen and upon successful login, I get back to the original page, where the FB Button now says "Log out" instead of "Log In"). However, I need a way to discern when a login was successful or not and obviously this does not work with a simple method, in which I check for button clicks. The reason I need to check for successful logins is that I need to set some tokens that are useful for user identification purposes. So how can I do that in Objective C?
you can use the "Custom Login Button" section on the following page:
https://developers.facebook.com/docs/facebook-login/ios
To check if the user is currently logged in or not
if ([FBSDKAccessToken currentAccessToken]) {
// User is logged in, do work such as go to next view controller.
}

addtarget on Facebook (standard) login button

This regards the STANDARD Facebook login button, not the custom one.
Im wondering if its not possible to use some delegate method or callback in response to a successful Facebook-login. Im basically trying to present a new view controller after returning to the app (from browser Facebook). First I tried adding a selector to the login button, but the selector is never called on click, so for some reason I think this is only allowed when creating a custom Facebook login.. I did create a custom, but it just seems overkill for what I'm trying to do (plus I have to manually handle logged in /loggedout). Isn't there some way to respond to login success on the default Facebook button?

Google + signin 'signInCallback' not triggered on signInButton load

To give sign in with google, I am using Google+ sign button in html as per this link https://developers.google.com/+/web/signin/add-button . In the documentation it is mentioned that, after loading the signIn button, the signInCallback will be triggered with authResult, then we can proceed with our function on successful login.In my case, I am having signIn button in say example.com#signIn url only. Once successfully signed in, page will be different say example.com#homePage. Note : Not having signIn button in any other page
Similarly on logout, I need to call gapi.auth.signOut() function. This url https://developers.google.com/+/web/signin/sign-out says :
This method must be called after your sign-in button's callback has fired. A new authorization result object is passed to your sign-in callback function, this object will contain the user_signed_out value in its error property. When you detect this value, you can reset your client state and notify your server (if applicable) that the user has signed out.
To achieve this scenario, I am loading page which will render signInButton,then when signincallback get triggered, I am using gapi.auth.signOut(). But the issue I am facing is, when the page is loaded, sometime the signIncallback is triggered, sometime not getting triggered.
May I know what the issue could be?

Making user follow another user can get its twitter username

I have a button on my website which says "Follow"
When a user clicks on this button I want the following to happen:
Twitter login window opens
User enters user/password and logs in
User has now started following
That login window now closes (or a close button clicking on which closes the window) and user is back on my website and I get its twitter username through some API which user just entered so I can insert it in my database.
Is this possible?
What I want to achieve is, I want to get username of users who follow me and save them in database.
In case #penartur's answer doesn't work for you, you may want to look at: https://dev.twitter.com/docs/intents/events. Although I have to admit that I've never used it : )

Resources