diff --git a/src/index.js b/src/index.js index f50ad7b42c07010d3e1f1ac04eb35eca0ba6b635..00972141928b56938ed89f65966e05ace4f86bf3 100755 --- a/src/index.js +++ b/src/index.js @@ -80,7 +80,12 @@ async function start(fields, cozyParameters) { ) } - const { pce, email, firstname, lastname, postalCode } = fields + let { pce, email, firstname, lastname, postalCode } = fields + + if (!pce && fields?.oauth_callback_results?.pce) { + pce = fields.oauth_callback_results.pce + log('info', `OAuth callback result found, using pce ${pce}`) + } const transaction = Sentry.startTransaction({ op: 'konnector', @@ -102,6 +107,11 @@ async function start(fields, cozyParameters) { const boUrlGRDF = new URL('/api/grdf', boBaseUrl).href try { + if (!pce) { + log('error', 'No PCE found') + throw errors.VENDOR_DOWN + } + log('info', `using PCE: ${pce}`) const { access_token } = await getAuthToken(grdfId, grdfSecret) const consents = await getConsents(access_token, pce) const noValidConsent = await handleConsents(consents, boUrlGRDF, boToken) diff --git a/src/types.ts b/src/types.ts index e7195d08a9a85f08cbb5d55fcd07ff6f711126fc..e7c8bfda085fc6ddb23689c15dc29cc4de3aaa62 100644 --- a/src/types.ts +++ b/src/types.ts @@ -44,6 +44,10 @@ export type fields = { lastname: string firstname: string postalCode: string + /** previous PCE from oauth stored in account */ + oauth_callback_results?: { + pce?: string + } } /** Cozy parameters definition */