diff --git a/index.js b/index.js index 49509c12606063cb54f8f0db25e9379a2852484f..e49d867e09838e049d0437a43fb2bba4bfbe4323 100644 --- a/index.js +++ b/index.js @@ -146,7 +146,10 @@ async function start(fields, cozyParameters, doRetry = true) { ',' ) usage_point_id = usage_points_id[0] - } else { + } else if (fields.usage_point_id) { + // In case of refresh token, we retrieve the usage point id from the fields + usage_point_id = fields.usage_point_id + }else { log('error', 'no usage_point_id found') throw errors.USER_ACTION_NEEDED_OAUTH_OUTDATED } @@ -185,6 +188,7 @@ async function start(fields, cozyParameters, doRetry = true) { log('info', 'refresh response') log('info', JSON.stringify(body)) fields.access_token = body.attributes.oauth.access_token + fields.usage_point_id = usage_point_id return start(fields, cozyParameters, false) } log('error', `Error during authentication: ${err.message}`)