3

I can successfully login with yam.platform.login but when I call

 yam.getLoginStatus(
     function (response) {
         if (response.authResponse) {
             yam.platform.logout(function (response) {
                 if (response) {
                     alert("logout success");
                 }
             })
         }
     }
 );

the inner callback function is never reached. Do people know what is happening?

EDIT: another strange behavior that could be related to the problem: after the above logout function call, the login status is still "connected" and I checked in Chrome that all cookies from yammer.com are deleted. But when I manually ask Chrome to delete the cookies, login status would return "unconnected".

Chuanqi Sun
  • 1,123
  • 14
  • 26

2 Answers2

0

Response from yam.platform.logout seems "false" after successful logout so you might try "if(response == false)" or even without if statement..

Community
  • 1
  • 1
0

I was also facing the same issue. It is hard to believe that the issue still exists in 2018! I dug a bit more and found that after the app is authorized by user, Yammer server sends a cookie which gets stored in the browser somewhere (not tied to the session) and yam.platform.logout is unable to delete this cookie (Ideally it should!)

But I found a good workaround which is working neatly for me.

Below is JS in my login page:

$("#yammer-login").click(function(){
        console.log("clicked");

         yam.getLoginStatus(
  function(resp) {
      yam.platform.login(function (response) { //prompt user to login and authorize your app, as necessary
            if (response.authResponse) {
              console.dir(response); //print user information to the console
                alert("login success");
            }
            $.ajax({
            type:"POST",
            url:"/setSession",
            data:JSON.stringify(response,null,'\t'),
            contentType:"application/json;charset=UTF-8",
            success: function(result){
              alert("Result from setSession is: "+result);
              window.location.replace("/login");
            }});

          });

      }
    );
    });

Here #yammer-login is the id for login element

<h2 class="sign-in">
          <center>
                 Sign-in With Yammer
                 <br><br>
                 <span id="yammer-login">Click</span>
          </center>
</h2>

Here is my workflow:

The JS on login page sends a POST request to setSession and sets the session. The execution of window.location.replace("/login"); sends a GET request to my server for /login url. As the session is now set, my server then redirects this request to the dashboard. After I click on logout button on the dashboard. I clear all the session cookies and redirect it back to the login page. As the session is now un-set- I see the login page again! All works smooth!

So, the next time user clicks on #yammer-login DOM element - the session gets set and she gets redirected to dashboard (this time without authorizing the app)!

Hope this helps someone who faces this issue like me in the future!

Vimanyu
  • 625
  • 2
  • 9
  • 24