diff --git a/.gitignore b/.gitignore index 583bf4a..78ffe74 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules/ _private/ +.idea/ diff --git a/carelink.js b/carelink.js index d36f5f4..f905fab 100644 --- a/carelink.js +++ b/carelink.js @@ -16,8 +16,10 @@ var CARELINKEU_SERVER_ADDRESS = 'https://' + carelinkServerAddress; var CARELINKEU_LOGIN1_URL = 'https://' + carelinkServerAddress + '/patient/sso/login?country=gb&lang=en'; var CARELINKEU_LOGIN3_URL = 'https://mdtlogin.medtronic.com/mmcl/auth/oauth/v2/authorize/login?country=gb&lang=en'; var CARELINKEU_LOGIN4_URL = 'https://mdtlogin.medtronic.com/mmcl/auth/oauth/v2/authorize/consent'; +var CARELINKEU_REFRESH_TOKEN_URL = 'https://' + carelinkServerAddress + '/patient/sso/reauth'; var CARELINKEU_JSON_BASE_URL = 'https://' + carelinkServerAddress + '/patient/connect/data?cpSerialNumber=NONE&msgType=last24hours&requestTime='; -var CARELINKEU_LOGIN_COOKIE = 'auth_tmp_token'; +var CARELINKEU_TOKEN_COOKIE = 'auth_tmp_token'; +var CARELINKEU_TOKENEXPIRE_COOKIE = 'c_token_valid_to'; var CARELINK_SECURITY_URL = 'https://' + carelinkServerAddress + '/patient/j_security_check'; var CARELINK_AFTER_LOGIN_URL = 'https://' + carelinkServerAddress + '/patient/main/login.do'; @@ -44,12 +46,12 @@ function reqOptions(extra) { return _.merge(defaults, extra); } -function haveLoginCookie(jar) { +/*function haveLoginCookie(jar) { if (CARELINK_EU) - return _.some(jar.getCookies(CARELINKEU_SERVER_ADDRESS), {key: CARELINKEU_LOGIN_COOKIE}); + return _.some(jar.getCookies(CARELINKEU_SERVER_ADDRESS), {key: CARELINKEU_TOKEN_COOKIE}); else return _.some(jar.getCookies(CARELINK_SECURITY_URL), {key: CARELINK_LOGIN_COOKIE}); -} +}*/ function responseAsError(response) { if (!(response.statusCode >= 200 && response.statusCode < 400)) { @@ -88,6 +90,18 @@ var Client = exports.Client = function (options) { var jar = request.jar(); + function getCookies() { + return jar.getCookies(CARELINK_EU ? CARELINKEU_SERVER_ADDRESS : CARELINK_SECURITY_URL); + } + + function haveCookie(cookieName) { + return _.some(getCookies(), {key: cookieName}); + } + + function getCookie(cookieName) { + return _.find(getCookies(), {key: cookieName}); + } + if (options.maxRetryDuration === undefined) { options.maxRetryDuration = DEFAULT_MAX_RETRY_DURATION; } @@ -187,7 +201,7 @@ var Client = exports.Client = function (options) { let ps = params(response.request.body); const regex = /(