Marplex / flarebase-auth

Firebase/Admin Auth Javascript Library for Cloudflare Workers
https://dev.to/marplex/firebase-authentication-on-cloudflare-workers-24o3
MIT License
88 stars 14 forks source link

createSessionCookie failing on importPKCS8 on Cloudflare Pages #2

Closed arlair closed 1 year ago

arlair commented 1 year ago

InvalidCharacterError: atob() called with invalid base64-encoded data. (Only whitespace, '+', '/', alphanumeric ASCII, and up to two terminal '=' signs when the input data length is divisible by 4 are allowed.) when I look at the error to the Cloudflare Functions log.

Did you do anything special to get the certificate to work with FIREBASE_ADMIN_PRIVATE_KEY? In .env I had to wrap it in double quotes, but I have tried with and without in the Cloudflare environment variables through the dashboard as well as encrypting the environment variable.

The certificate looks fine in the logs (apart from \n escaping for the newline, but I assume that is just the JSON escaping.

I also tried to update all the dependencies included jose and deployed my own package (which I can make a commit back here for), but that did not seem to solve the problem.

Thanks for the great project.

arlair commented 1 year ago

I think adding this fixed it:

FIREBASE_ADMIN_PRIVATE_KEY.replace(/\\n/g, '\n')