loopback icon indicating copy to clipboard operation
loopback copied to clipboard

Non-authenticated POSTing to /User/logout produces an error 500

Open doublemarked opened this issue 11 years ago • 9 comments

The User.logout code appears to do this intentionally. It feels like the wrong error response code, but I don't know what the correct code is. Here is the User.logout code, for reference,

  User.logout = function(tokenId, fn) {
    this.relations.accessTokens.modelTo.findById(tokenId, function(err, accessToken) {
      if (err) {
        fn(err);
      } else if (accessToken) {
        accessToken.destroy(fn);
      } else {
        fn(new Error('could not find accessToken'));
      }
    });
  };

Please advise if that is the intended functionality or not.

doublemarked avatar Jun 26 '15 17:06 doublemarked

Maybe 400 is better. Do you want to submit a patch?

raymondfeng avatar Jun 26 '15 17:06 raymondfeng

  1. User.logout requires logged-in user. And as any other protected method it has to return 401.

rus0000 avatar Jun 26 '15 19:06 rus0000

Perhaps the problem here is just that the ACL is wrong?

    {
      "principalType": "ROLE",
      "principalId": "$everyone",
      "permission": "ALLOW",
      "property": "logout"
    },

doublemarked avatar Jun 26 '15 19:06 doublemarked

principalId has to be $authenticated

rus0000 avatar Jun 27 '15 14:06 rus0000

@raymondfeng can you confirm that the ACL is off? If so, I'm happy to put together a patch.

doublemarked avatar Jun 27 '15 20:06 doublemarked

@raymondfeng Assigning to you since you are already working on this.

superkhau avatar Jul 06 '15 18:07 superkhau

A missing or invalid access token should return a 401 per HTTP 1.1 RFC. See my response to related issue: https://github.com/strongloop/loopback/issues/1496

kevintechie avatar Nov 17 '15 19:11 kevintechie

I'm also having the 500 error. I'm essentially using the same AuthService and controllers that came with the loopback-getting-started-intermediate.

The only difference is the following, any ideas? Thanks in advance.

    $scope.login = function(e) {
      console.log('logging...');
      AuthService.login($scope.email, $scope.password)
        .then(function() {
          console.log('I am inside!');
           window.history.back();          
          //$state.go('add-review');
        },  
        function(err, token)
        {
          console.log(err);
          $scope.loginMsg = err.data.error.message;
        });
    };
  }])
  .controller('AuthLogoutController', ['$scope', 'AuthService', 'Helper',
      function($scope, AuthService, Helper) {
    AuthService.logout()
      .then(function() {
        //$state.go('all-reviews');
      });
  }])

benawarez avatar Nov 23 '15 21:11 benawarez

@doublemarked Original bug in this issue is fixed by PR https://github.com/strongloop/loopback/pull/1496 Will be closing this issue

rashmihunt avatar Jun 29 '17 22:06 rashmihunt