psn_request.js
function CheckTokens(callback, token_fetch)
	{
		// build list of tokens we're missing
		var todo = [];

		// force token_fetch to an array
		token_fetch = [].concat(token_fetch);

		// make sure we're actually logged in first
		if (!auth_obj.auth_code)
		{
			Log("Need to login - no auth token found");
			todo.push({name: "Login", func: Login});
		}

		if (!auth_obj.expire_time || auth_obj.expire_time < new Date().getTime())
		{
			// token has expired! Fetch access_token again
			Log("Need to fetch access tokens - tokens expired");
			todo.push({name: "GetAccessToken", func: GetAccessToken});
		}
		else if (!auth_obj.access_token)
		{
			// we have no access token (?!)
			Log("Need to fetch access tokens - no token available");
			todo.push({name: "GetAccessToken", func: GetAccessToken});
		}

		if (!auth_obj.username || !auth_obj.region)
		{
			// missing player username/region
			Log("Need to fetch userdata - no region or username available");
			todo.push({name: "GetUserData", func: GetUserData});
		}

		if (todo.length == 0)
		{
			// everything is fine
			if (callback) callback(false);
		}
		else
		{
			// work through our list of tokens we need to update
			var step = function()
			{
				var func = todo.shift();
				if (!func)
				{
					// all done!
					if (callback) callback(false);
					return;
				}

				if (token_fetch.indexOf(func.func) >= 0)
				{
					// if we're actually calling a token fetch function, skip!
					process.nextTick(step);
				}
				else
				{
					func.func(function(error) {
						if (error)
						{
							// token fetching error!
							if (callback) callback(func.name + " :: " + error);
							return;
						}

						// do next step
						process.nextTick(step);
					});
				}
			};

			// start updating tokens
			process.nextTick(step);
		}
	}
function CheckTokens(callback, token_fetch)
	{
		// build list of tokens we're missing
		var todo = [];

		// force token_fetch to an array
		token_fetch = [].concat(token_fetch);

		// make sure we're actually logged in first
		if (!auth_obj.auth_code)
		{
			Log("Need to login - no auth token found");
			todo.push({name: "Login", func: Login});
		}

		if (!auth_obj.expire_time || auth_obj.expire_time < new Date().getTime())
		{
			// token has expired! Fetch access_token again
			Log("Need to fetch access tokens - tokens expired");
			todo.push({name: "GetAccessToken", func: GetAccessToken});
		}
		else if (!auth_obj.access_token)
		{
			// we have no access token (?!)
			Log("Need to fetch access tokens - no token available");
			todo.push({name: "GetAccessToken", func: GetAccessToken});
		}

		if (!auth_obj.username || !auth_obj.region)
		{
			// missing player username/region
			Log("Need to fetch userdata - no region or username available");
			todo.push({name: "GetUserData", func: GetUserData});
		}

		if (todo.length == 0)
		{
			// everything is fine
			if (callback) callback(false);
		}
		else
		{
			// work through our list of tokens we need to update
			var step = function()
			{
				var func = todo.shift();
				if (!func)
				{
					// all done!
					if (callback) callback(false);
					return;
				}

				if (token_fetch.indexOf(func.func) >= 0)
				{
					// if we're actually calling a token fetch function, skip!
					process.nextTick(step);
				}
				else
				{
					func.func(function(error) {
						if (error)
						{
							// token fetching error!
							if (callback) callback(func.name + " :: " + error);
							return;
						}

						// do next step
						process.nextTick(step);
					});
				}
			};

			// start updating tokens
			process.nextTick(step);
		}
	}
function CheckTokens ( callback , token_fetch ) { // build list of tokens we're missing var todo = [ ] ; // force token_fetch to an array token_fetch = [ ] . concat ( token_fetch ) ; // make sure we're actually logged in first if ( ! auth_obj . auth_code ) { Log ( "Need to login - no auth token found" ) ; todo . push ( { name : "Login" , func : Login } ) ; } if ( ! auth_obj . expire_time || auth_obj . expire_time < new Date ( ) . getTime ( ) ) { // token has expired! Fetch access_token again Log ( "Need to fetch access tokens - tokens expired" ) ; todo . push ( { name : "GetAccessToken" , func : GetAccessToken } ) ; } else if ( ! auth_obj . access_token ) { // we have no access token (?!) Log ( "Need to fetch access tokens - no token available" ) ; todo . push ( { name : "GetAccessToken" , func : GetAccessToken } ) ; } if ( ! auth_obj . username || ! auth_obj . region ) { // missing player username/region Log ( "Need to fetch userdata - no region or username available" ) ; todo . push ( { name : "GetUserData" , func : GetUserData } ) ; } if ( todo . length == 0 ) { // everything is fine if ( callback ) callback ( false ) ; } else { // work through our list of tokens we need to update var step = function ( ) { var func = todo . shift ( ) ; if ( ! func ) { // all done! if ( callback ) callback ( false ) ; return ; } if ( token_fetch . indexOf ( func . func ) >= 0 ) { // if we're actually calling a token fetch function, skip! process . nextTick ( step ) ; } else { func . func ( function ( error ) { if ( error ) { // token fetching error! if ( callback ) callback ( func . name + " :: " + error ) ; return ; } // do next step process . nextTick ( step ) ; } ) ; } } ; // start updating tokens process . nextTick ( step ) ; } }
Check the session's tokens are still valid! token_fetch var is the function calling the token check in cases where the function is actually already fetching tokens!
Check the session s tokens are still valid! token_fetch var is the function calling the token check in cases where the function is actually already fetching tokens!