This is a migrated thread and some comments may be shown as answers.

{"message":"The provided access token is invalid or has expired","code":301}

4 Answers 248 Views
JavaScript SDK
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Bruce
Top achievements
Rank 1
Bruce asked on 03 Feb 2016, 03:24 AM

All,

I am using the Javascript SDK to create a new user and keep getting the error {"message":"The provided access token is invalid or has expired","code":301}.

I can see my App ID coming through in the service correctly, and when I see the URL that is called using chrome inspector, it appears to be valid and the AppID is the same as what is in the platform dashboard. I must be missing something...

Any and all help appreciated!

I am using my App ID in the following way:

app.js

.value('TelerikConfiguration', {
url: "//api.everlive.com/v1/",
applicationId: '123xyz'
})

UserSvc.js

angular.module('Bairfinder').
service('UserSvc', function(TelerikConfiguration) {
 
  var el = new Everlive({
      apiKey: TelerikConfiguration.applicationId,
      url: TelerikConfiguration.url,
      scheme: 'https',
      token: localStorage.getItem('sessionToken')
  });
 
  console.log('applicationId:' + TelerikConfiguration.applicationId);
  console.log('url:' + TelerikConfiguration.url);
 
  return {
 
    newAccount : {
      email: '',
      password:'',
      firstName:'',
      lastName:'',
      phone:'',
      hasAcceptedTerms:false,
      isAge18:false
    },
 
    currentUser: function(){
      //return Parse.User.current();
      return el.Users.currentUser();
    },
    loginUser: function(user, password) {
      //return Parse.User.logIn(user, password);
      return el.Users.login(user, password);
    },
    loginUserBySessionToken: function(sessionToken){
      console.log('loginUserBySessionToken:' + sessionToken);
      //var promise = Parse.User.become(sessionToken);
      var promise = el.authentication.setAuthorization(sessionToken, 'bearer');
      console.log(JSON.stringify(promise));
      return promise;
    },
    createUser: function(newAccount){
      var self = this;
      //if (newAccount.hasAcceptedTerms && newAccount.isAge18){
        var attrs = {
          email: newAccount.email,
          firstName: newAccount.firstName,
          lastName: newAccount.lastName,
          phone: newAccount.phone//,
          //ACL: new Parse.ACL()
        };
        //return Parse.User.signUp(self.newAccount.email, self.newAccount.password, attrs);
        return el.Users.register(self.newAccount.email, self.newAccount.password, attrs);
      //}
    },
    resetUserPwd: function(newAccount){
      var self = this;
      console.log('resetUserPwd:' + JSON.stringify(self));
      //return Parse.User.requestPasswordReset(self.newAccount.email);
      return el.users.resetPassword(newAccount);
    }
  };
});

 

4 Answers, 1 is accepted

Sort by
0
Anton Dobrev
Telerik team
answered on 04 Feb 2016, 05:28 PM
Hello Bruce,

Thanks for posting to the Telerik Developer Forums.

This error is returned from the server when the request sent to it is authenticating with an invalid or expired access token.

It appears that you are setting explicitly to the instance an access token (the token property of the Everlive) but it is no longer valid. Perhaps it may be a good idea to allow the SDK to handle this automatically (as explained here) or ensure that a valid access token is sent.

Let me know if this helps.

Regards,
Anton Dobrev
Telerik
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
0
Bruce
Top achievements
Rank 1
answered on 04 Feb 2016, 09:43 PM

Hi Anton,

Thanks for the reply. I didn't even see that. I moved the token assignment to the loginUserBySessionToken call where it belongs, but when I run the code without token, I am still seeing a token value in the el object and am still getting the same error. I assume that value must be cached, and if so, do you know how long it is cached for?

0
Bruce
Top achievements
Rank 1
answered on 05 Feb 2016, 11:54 AM

Anton,

FYI, I switched to using the REST API version, which I found to be easier to use with Angular, and had no issue creating the user. All good and moving forward...

0
Anton Dobrev
Telerik team
answered on 09 Feb 2016, 02:24 PM
Hello Bruce,

Good to see you were able to move forward with your development tasks.

Just a quick note, it appears that the Everlive instance was still sending a token because such was set to the token property of Everlive.

Let me know should you have further questions. 

Regards,
Anton Dobrev
Telerik
 
Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
 
Tags
JavaScript SDK
Asked by
Bruce
Top achievements
Rank 1
Answers by
Anton Dobrev
Telerik team
Bruce
Top achievements
Rank 1
Share this question
or