Skip to content

Commit

Permalink
update to latest release
Browse files Browse the repository at this point in the history
  • Loading branch information
uzquiano committed May 16, 2015
1 parent 068800f commit e9d18b0
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 7 deletions.
66 changes: 61 additions & 5 deletions lib/gitana.js
Original file line number Diff line number Diff line change
Expand Up @@ -2164,8 +2164,9 @@ if (typeof JSON !== 'object') {
* Disconnects a platform from the cache.
*
* @param key
* @param expireAccessToken
*/
Gitana.disconnect = function(key)
Gitana.disconnect = function(key, expireAccessToken)
{
if (!key) {
key = "default";
Expand All @@ -2174,6 +2175,18 @@ if (typeof JSON !== 'object') {
var platform = Gitana.PLATFORM_CACHE(key);
if (platform)
{
// if we are meant to expire the server-side access token,
// fire off a signal to the Cloud CMS server to do so
// we ignore whether this succeeds or fails
if (expireAccessToken)
{
platform.getDriver().gitanaPost("/auth/expire", {}, {}, function() {
// success
}, function(err) {
// error
});
}

var badKeys = [];
for (var k in Gitana.APPS)
{
Expand Down Expand Up @@ -2959,7 +2972,7 @@ if (typeof JSON !== 'object') {
if (this.authorizationFlow == Gitana.OAuth2Http.TOKEN)
{
var existingAccessToken = this.accessToken();
if (existingAccessToken != options.accessToken)
if (existingAccessToken !== options.accessToken)
{
storage.clear();
}
Expand Down Expand Up @@ -3011,6 +3024,8 @@ if (typeof JSON !== 'object') {
self.expiresIn(_expiresIn);
self.grantedScope(_grantedScope);
self.grantTime(_grantTime);

// console.log("doGetAccessToken -> " + JSON.stringify(object));
}

success();
Expand Down Expand Up @@ -3117,6 +3132,8 @@ if (typeof JSON !== 'object') {
self.expiresIn(_expiresIn);
self.grantedScope(_grantedScope);
self.grantTime(_grantTime);

// console.log("doRefreshAccessToken -> " + JSON.stringify(object));
}

success();
Expand Down Expand Up @@ -3276,9 +3293,45 @@ if (typeof JSON !== 'object') {
self.invoke(o);
};

// if we have an access token and it's about to expire (within 20 seconds of it's expiry),
// we force an early refresh of the access token so that concurrent requests don't get access problems
// this is important for any browser-originated requests that rely on a persisted cookie (GITANA_TICKET)
//
// also provide some debugging if needed
var forceRefresh = false;
if (self.accessToken())
{
var grantTime = self.grantTime();
if (grantTime)
{
var expiresIn = self.expiresIn();
if (expiresIn)
{
// NOTE: expiresIn is in seconds
var expirationTimeMs = self.grantTime() + (self.expiresIn() * 1000);
var nowTimeMs = new Date().getTime();

var timeRemainingMs = expirationTimeMs - nowTimeMs;
if (timeRemainingMs <= 0)
{
// console.log("Access Token is expired, refresh will be attempted!");
}
else
{
// console.log("Access Token Time Remaining: " + timeRemainingMs);
}

if (timeRemainingMs <= 20000)
{
// console.log("Access Token only has 20 seconds left, forcing early refresh");
forceRefresh = true;
}
}
}
}

// if no access token, request one
if (!self.accessToken() && !this.cookieMode && !this.ticketMode)
if ((!self.accessToken() || forceRefresh) && !this.cookieMode && !this.ticketMode)
{
if (!self.refreshToken())
{
Expand Down Expand Up @@ -3522,6 +3575,7 @@ if (typeof JSON !== 'object') {
*
* @param key
* @param value
*
* @return {*}
*/
r.poke = function(key, value)
Expand Down Expand Up @@ -11787,11 +11841,13 @@ Gitana.OAuth2Http.TOKEN_METHOD = "POST";
/**
* Clears authentication against the server.
*
* @param expireAccessToken (optional, assumed false)
*
* @chained server
*
* @public
*/
logout: function()
logout: function(expireAccessToken)
{
var self = this;

Expand All @@ -11800,7 +11856,7 @@ Gitana.OAuth2Http.TOKEN_METHOD = "POST";
var platformCacheKey = this.getDriver().platformCacheKey;
if (platformCacheKey)
{
Gitana.disconnect(platformCacheKey);
Gitana.disconnect(platformCacheKey, expireAccessToken);
}

this.getDriver().clearAuthentication();
Expand Down
2 changes: 1 addition & 1 deletion lib/gitana.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Gitana Software, Inc. <info@cloudcms.com> (http://www.cloudcms.com)",
"name": "gitana",
"description": "Cloud CMS Gitana Driver for Node JS",
"version": "1.0.156",
"version": "1.0.157",
"repository": {
"type": "git",
"url": "git://github.com/gitana/gitana-node-js.git"
Expand Down

0 comments on commit e9d18b0

Please sign in to comment.