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

5 posts, 0 answers
  1. Bruce
    Bruce avatar
    6 posts
    Member since:
    Jan 2016

    Posted 02 Feb Link to this post

    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);
        }
      };
    });

     

  2. Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 04 Feb Link to this post

    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.
     
  3. Bruce
    Bruce avatar
    6 posts
    Member since:
    Jan 2016

    Posted 04 Feb in reply to Anton Dobrev Link to this post

    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?

  4. Bruce
    Bruce avatar
    6 posts
    Member since:
    Jan 2016

    Posted 05 Feb in reply to Bruce Link to this post

    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...

  5. Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 09 Feb Link to this post

    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.
     
Back to Top