web-auth-library
web-auth-library copied to clipboard
getAccessToken not working on Cloudflare Workers
The function
const accessToken = await getAccessToken({
credentials: credentials,
scope: "https://www.googleapis.com/auth/cloud-platform",
waitUntil: c.executionCtx.waitUntil,
});
Isn't working for me, it works locally, but when I use it in the worker it says this: TypeError: Illegal invocation
Anyone faced the same problem?
I have the same problem, did you solve it ?
@zewelor I stopped using this library and I used this instead.
@zewelor I stopped using this library and I used this instead.
Hmm i see link to this ( web-auth-library ) library
Same issue here.
Use waitUntil: ctx.waitUntil.bind(ctx)
instead.
Use
waitUntil: ctx.waitUntil.bind(ctx)
instead.
but I got '{}' from my firestore.
I tried it today and I'm getting following info:
TypeError: Illegal invocation: function called with incorrect `this` reference. See https://developers.cloudflare.com/workers/observability/errors/#illegal-invocation-errors for details.
A ReadableStream branch was created but never consumed. Such branches can be created, for instance, by calling the tee() method on a ReadableStream, or by calling the clone() method on a Request or Response object. If a branch is created but never consumed, it can force the runtime to buffer the entire body of the stream in memory, which may cause the Worker to exceed its memory limit and be terminated. To avoid this, ensure that all branches created are consumed.
* Unused stream created:
at null.<anonymous> (file:///C:/projects/parcels-api/node_modules/web-auth-library/dist/google/accessToken.js:105:36)
at async getAccessToken (file:///C:/projects/parcels-api/node_modules/web-auth-library/dist/google/accessToken.js:127:12)
at async getFirebaseToken (file:///C:/projects/parcels-api/src/utils/firebase-auth.ts:21:23)
at async getAuthHeaders (file:///C:/projects/parcels-api/src/clients/firestore-client.ts:8:17)
at async getUserAvailableCoverage (file:///C:/projects/parcels-api/src/clients/firestore-client.ts:17:19)
at null.<anonymous> (async file:///C:/projects/parcels-api/.wrangler/tmp/dev-RVTltV/index.js:39419:38)
at async dispatch (file:///C:/projects/parcels-api/node_modules/hono/dist/compose.js:29:17)
at async cors2 (file:///C:/projects/parcels-api/node_modules/hono/dist/middleware/cors/index.js:65:5)
at async dispatch (file:///C:/projects/parcels-api/node_modules/hono/dist/compose.js:29:17)
at async poweredBy2 (file:///C:/projects/parcels-api/node_modules/hono/dist/middleware/powered-by/index.js:4:5)
@arekgotfryd I had the same issue when using CF Workers without hono
and executionCtx
.
Here's how I ended up solving...
return getAccessToken({
credentials: env.GOOGLE_CLOUD_CREDENTIALS,
scope: 'https://www.googleapis.com/auth/cloud-translation',
waitUntil: ctx.waitUntil.bind(ctx),
env,
});
Note how the waitUntil
function is re-bound to (CF Worker native) ctx.