psn_request.js
function GetAccessToken(callback)
	{
		// do we have a refresh token? Or do we need to login from scratch?
		if (auth_obj.refresh_token)
		{
			// we have a refresh token!
			Log("Refreshing session...");

			if (!auth_obj.refresh_token)
			{
				if (callback) callback("No refresh token found!");
				return;
			}

			// request new access_token
			request.post(
				{
					url: urls.oauth,
					form: GetOAuthData({
						"grant_type": 		"refresh_token",
						"refresh_token": 	auth_obj.refresh_token
					})
				},
				function(err, response, body)
				{
					_ParseTokenResponse(err, body, callback);
				}
			);
		}
		else
		{
			// no refresh token, sign-in from scratch
			Log("Signing in with OAuth...");

			// make sure we have an authcode
			if (!auth_obj.auth_code)
			{
				if (callback) callback("No authcode available for OAuth!");
				return;
			}

			// request initial access_token
			request.post(
				{
					url: urls.oauth,
					form: GetOAuthData({
						"grant_type": 	"authorization_code",
						"code": 		auth_obj.auth_code
					})
				},
				function(err, response, body)
				{
					_ParseTokenResponse(err, body, callback);
				}
			);
		}
	}
function GetAccessToken(callback)
	{
		// do we have a refresh token? Or do we need to login from scratch?
		if (auth_obj.refresh_token)
		{
			// we have a refresh token!
			Log("Refreshing session...");

			if (!auth_obj.refresh_token)
			{
				if (callback) callback("No refresh token found!");
				return;
			}

			// request new access_token
			request.post(
				{
					url: urls.oauth,
					form: GetOAuthData({
						"grant_type": 		"refresh_token",
						"refresh_token": 	auth_obj.refresh_token
					})
				},
				function(err, response, body)
				{
					_ParseTokenResponse(err, body, callback);
				}
			);
		}
		else
		{
			// no refresh token, sign-in from scratch
			Log("Signing in with OAuth...");

			// make sure we have an authcode
			if (!auth_obj.auth_code)
			{
				if (callback) callback("No authcode available for OAuth!");
				return;
			}

			// request initial access_token
			request.post(
				{
					url: urls.oauth,
					form: GetOAuthData({
						"grant_type": 	"authorization_code",
						"code": 		auth_obj.auth_code
					})
				},
				function(err, response, body)
				{
					_ParseTokenResponse(err, body, callback);
				}
			);
		}
	}
function GetAccessToken ( callback ) { // do we have a refresh token? Or do we need to login from scratch? if ( auth_obj . refresh_token ) { // we have a refresh token! Log ( "Refreshing session..." ) ; if ( ! auth_obj . refresh_token ) { if ( callback ) callback ( "No refresh token found!" ) ; return ; } // request new access_token request . post ( { url : urls . oauth , form : GetOAuthData ( { "grant_type" : "refresh_token" , "refresh_token" : auth_obj . refresh_token } ) } , function ( err , response , body ) { _ParseTokenResponse ( err , body , callback ) ; } ) ; } else { // no refresh token, sign-in from scratch Log ( "Signing in with OAuth..." ) ; // make sure we have an authcode if ( ! auth_obj . auth_code ) { if ( callback ) callback ( "No authcode available for OAuth!" ) ; return ; } // request initial access_token request . post ( { url : urls . oauth , form : GetOAuthData ( { "grant_type" : "authorization_code" , "code" : auth_obj . auth_code } ) } , function ( err , response , body ) { _ParseTokenResponse ( err , body , callback ) ; } ) ; } }
Get an access token using the PSN oauth service using our current auth config
Get an access token using the PSN oauth service using our current auth config