0

I am trying to add a logout call into a front end app that i'm building, that uses SF for the auth features. When logging in, i successfully get the instance url, profile string and access token as expected.

However, when i try to call the logout string, it always throws an error and never kills the session in SF. Here is my express code:

router.get(
      '/auth/logout',
      requireLogin,
      (req, res) => {
        console.log(`about to call this url: ${req.user.sfInstanceUrl}/services/oauth2/revoke?token=${req.user.sfAccessToken}`)
        // call the url to logout from Salesforce
        axios.get(`${req.user.sfInstanceUrl}/services/oauth2/revoke?token=${req.user.sfAccessToken}`,{
          'Authorization': 'Bearer ' + req.user.sfAccessToken
        })
        .then(result => {
          console.log(`was there any result from the axios call? ${JSON.stringify(result)}`);
          req.session.destroy();
          res.redirect('/');  
        }).catch( err => {
          console.log(`we caught an error: ${JSON.stringify(err)}`);
          req.session.destroy();
          res.redirect('/');
        }); 
      }
    );

Now, when this gets executed, i always end up in the error block with a status 400 error and little other information... The get URL that is logged out at the top looks correct. When i try this flow in postman, it works and the session gets killed and i get a status 200 back from salesforce...

Is there something i've missed in that GET request? The documentation still says that GET requests are supported for logout - but this one doesn't work..

  • 1
    For one, you don't need the Authorization header. The error message is probably in the body of the response. If you can reproduce the issue with a command-line client such as curl and post the request/response, it would help. Postman does not count as a command-line client. Depending on its config, Postman auto-adds headers and messes with input/output. – identigral Sep 19 at 18:38
  • 1
    the actual issue was in my postman handler. upon subsequent logins i wasn't updating the originally stored access token with the new one returned from the auth flow... code is hard :| thanks for the nudge in the right direction identigral :) This really helped.. – adam.sellers Sep 21 at 21:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.