QuickBlox QB.chat.connect giving perplexing authentication error code 401 out of nowhere

893 views Asked by At

I've been getting my hands into a Quickblox app and everything has been going fine (at least insofar as logging in with the users accounts..) up until this afternoon when I started to get a perplexing user authentication error like so:

108 606756 log [QBChat]:, Status.AUTHFAIL - The authentication attempt failed 109 606758 log stringifying the err... {"code":401,"status":"error","message":"Unauthorized","detail":"Status.AUTHFAIL - The authentication attempt failed"}

When debugging in Chome, the XML in the QBChat can be expanded and it says 'Password not verified', which is perplexing since the password is definitely right.

Edit: I'm positive the password is correct, because it always logs into QuickBlox successfully first, but then fails occasionally when trying to log into the QB.CHAT server.

I can't tell what is causing this. I try logging out to log back in on a blank slate - sometimes that 'works', other times it doesn't - so it might be that quickblox is just randomly as far as I can tell deciding to work

  $scope.signInClick = function() {
    console.log('Login was clicked');
     
      $scope.loading = $ionicLoading.show({
          content: 'Logging in',
          animation: 'fade-in',
          showBackdrop: true,
          maxWidth: 200,
          showDelay: 0
      });

      var params = {'login': ($scope.user.username), 'password': ($scope.user.password)}
      console.log("params... " + JSON.stringify(params));

      QB.users.create(params, function(err, user){
        if (user) {
          console.log("successful user.create... " + JSON.stringify(user));
          var jid = user.id + "-23837" + "@chat.quickblox.com";
          console.log(user.login + "'s jid is......" + jid);
          var chatparams = {'jid': jid, 'password': ($scope.user.password)};
          QB.chat.connect(chatparams, function(err, roster) {
            console.log("err from qb.chat.connect... " + JSON.stringify(err));
            console.log("roster from qb.chat.connect .... " + JSON.stringify(roster));
          });
        } 
        else  {
          console.log(JSON.stringify(err));
          if (err.message == "Unprocessable Entity"){
            QB.login(params, function(err, user){
              if (user) {
                console.log("Logged into QB with " + JSON.stringify(user));
                var jid = user.id + "-23837" + "@chat.quickblox.com";
                console.log(user.login + "'s jid is......" + jid);
                var chatparams = {'jid': jid, 'password': ($scope.user.password)};
                QB.chat.connect(chatparams, function(err, roster) {
                  console.log("stringifying the err... " + JSON.stringify(err));
                  console.log("stringifying the roster... " + JSON.stringify(roster));
                });
              } 
              else  {
                console.log(JSON.stringify(err));
              }
            });
          }
        }
      });

There's the code I'm running in the controller... it is still happening, randomly, sometimes a lot of errors in a row, other times it will error and then work and then error then work and work then error then work and so on.

2

There are 2 answers

0
realisation On BEST ANSWER

Ah so it turns out that the problem was Angular JS. I changed the params from accepting $scope.user.password in the callbacks to using the params.password from the param object created to go into the first callback, and it works every time now.

The error code received was the correct one, and here is another lesson never to stop investigating a particular trend until you get down to brass tacks.

Instead of assuming the password was correct because it successfully completed the first QB func every time, further investigation would have shown that the angular was failing to provide the variable to the chatparams object, such that the field password was not included in it - just {jid: '[email protected]'}.

2
Rubycon On

"Unauthorized" and "Password not verified" means what it means - your password for chat login is incorrect.

Maybe you changed it via API or in Admin panel?

If it sometimes works - can you post your code, will try to verify what can be the cause