2017-12-05 7 views
-2

Ich wollte eine Cloud-Code-Funktion erstellen, die mir hilft, das Datum des ExpiresAt-Feldwerts des Sitzungstokens in Parse Server zu ändern. Gibt es eine Möglichkeit, dies zu tun? oder eine API, auf die ich verweisen kann?Verlängert Sitzungstoken ExpiresAt

Vielen Dank.

Antwort

1

Ich beende meine eigene Frage. Nach manchmal, fand ich, dass ich eine CloudCode-Funktion wie unten für die Erweiterung Session Token erstellen kann, HOpe das hilft anderen.

Parse.Cloud.define("extendSessionToken", function(request, response) 
{ 
    req({ 
     method: 'GET', 
     url: process.env.SERVER_URL + "/sessions/me", 
     headers: 
     { 
      'X-Parse-Application-Id': process.env.APP_ID, 
      'X-Parse-REST-API-Key': process.env.REST_API_KEY, 
      'X-Parse-Session-Token': request.headers["x-parse-session-token"], 
      'X-Parse-Master-Key' : process.env.MASTER_KEY 
     }   
    }, function (error, httpResponse, body) 
    { 
     var jsonBody = JSON.parse(body); 
     DLog.info(JSON.stringify(jsonBody)); 
     if(error) 
     {    
      handleResponseReturn(response, 1, error); 
     } 
     else if(jsonBody.error) 
     {    
      handleResponseReturn(response, 1, jsonBody.error); 
     } 
     else 
     {    
      var newSessionYear = new Date(); 
      newSessionYear.setFullYear(newSessionYear.getFullYear() + 1); 
      var newSessionBody = { 
       'expiresAt': Parse._encode(newSessionYear) 
      } 

      DLog.info("New ExpiresAt: " + JSON.stringify(newSessionBody)); 
      req({ 
        method: 'PUT', 
        url: process.env.SERVER_URL + "/sessions/" + jsonBody.objectId, 
        headers: 
        { 
         'X-Parse-Application-Id': process.env.APP_ID, 
         'X-Parse-REST-API-Key': process.env.REST_API_KEY, 
         'Content-Type': 'application/json;charset=utf-8', 
         'X-Parse-Session-Token': request.headers["x-parse-session-token"], 
         'X-Parse-Master-Key' : process.env.MASTER_KEY 
        }, 
        body: JSON.stringify(newSessionBody) 
       }, function (error, httpResponse, body) 
       { 
        var jsonResult = JSON.parse(body); 
        if(error) 
         handleResponseReturn(response, 1, error); 
        else if(jsonBody.error) 
         handleResponseReturn(response, 1, jsonBody.error); 
        else 
         handleResponseReturn(response, 0, body); 
       }); 
     } 
    }); 
}); 

Hope this hilft denen, die die gleichen Probleme konfrontiert sind. Fühlen Sie sich frei, dies zu nehmen und zu modifizieren, wie Sie möchten.

Verwandte Themen