Results 1 to 3 of 3

Thread: How to renew access token

  1. #1
    Sencha User
    Join Date
    Nov 2015
    Location
    Romania,Timisoara
    Posts
    14
    Answers
    2

    Default Answered: How to renew access token

    Hello, i would kindly ask you for a help. Right now we use oauth and we store the token on front end. We also run a task which gets a new access token using the refresh token every 5 minutes. We would like to implement a global solution so that we make the usual requests, and if the access token expired , we identify this by status code, and afterwards get a new access token. We figured out to use Ext.util.Observable.observe on Ext.data.Connection to identify the failed requests. The only challenge we have is to recall again the requests that failed after getting the new access token.

    example:
    1. i make a get request to a list
    2. request fails, the token is expired, i get a status code 401 (unauthorized)
    3. from the observable i see that the access_token is expired
    4. i get a new access_token
    5. i make a get request to a list again with the new token
    Stept 5 is our problem. If you have any idea, please help us.

    Thank you!!

  2. Found a solution:
    PHP Code:

    Ext
    .util.Observable.observe(Ext.data.Connection, {
      
    requestexception: function(connresponseoptions) {
        if((
    response) && (response.status === 401 && response.statusText === "Unauthorized"))
        {
           
    Mvp.util.Util.getNewToken();
           
    conn.request(options, {
              
    callback: function() {
                 
    conn.resumeEvents();
              }
          });
         }
    ............ 

  3. #2
    Sencha User
    Join Date
    Nov 2015
    Location
    Romania,Timisoara
    Posts
    14
    Answers
    2

    Default

    Found a solution:
    PHP Code:

    Ext
    .util.Observable.observe(Ext.data.Connection, {
      
    requestexception: function(connresponseoptions) {
        if((
    response) && (response.status === 401 && response.statusText === "Unauthorized"))
        {
           
    Mvp.util.Util.getNewToken();
           
    conn.request(options, {
              
    callback: function() {
                 
    conn.resumeEvents();
              }
          });
         }
    ............ 

  4. #3
    Sencha User
    Join Date
    Feb 2013
    Location
    California
    Posts
    11,985
    Answers
    506

    Default

    Glad to see that you found a solution, and thanks for sharing with the community.

Similar Threads

  1. Buy Extended Sencha Support and get 6 months free plus get rights to Ext JS 6
    By mitchellsimoens in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 19 May 2015, 10:33 AM
  2. Facebook Graph API renew access token automatically
    By NielsVerhesen in forum Sencha Touch 2.x: Q&A
    Replies: 5
    Last Post: 19 Jul 2012, 3:12 AM
  3. CSRF token in Django
    By env0ke in forum Ext: Discussion
    Replies: 0
    Last Post: 25 May 2011, 11:56 PM
  4. Reload / renew some panels after login
    By Toon in forum Ext 3.x: Help & Discussion
    Replies: 4
    Last Post: 8 Mar 2010, 6:40 AM
  5. Adding a Token
    By boriscy in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 26 Mar 2008, 11:03 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •