wasp-lang / open-saas

A free, open-source SaaS app starter for React & Node.js with superpowers. Full-featured. Community-driven.
https://opensaas.sh
MIT License
8.2k stars 791 forks source link

Chrome extension usage to handle token exchange #274

Open yashomi-t3h opened 1 month ago

yashomi-t3h commented 1 month ago

I am planning to develop chrome extenstion where the user is required to sign in using google oauth. For extension to initiate flow it would call a method called chrome.identity.launchWebAuthFlow

From this call I am able to fetch code, access_token and id_token

https://.chromiumapp.org/#state=8v9lwh &code= "code starting with 4 " &access_token="starting with ya29" &id_token="starting with ey"

I see in browser when doing oAuth you use the IDtoken and exchange it via API using following request to get the bearer token. However this gives me error for the token I recieved using chrome extention ( method chrome.identitylauchWebflow)

POST {{api-host}}/auth/exchange-code HTTP/1.1 Content-Type: application/json Accept: application/json Origin: http://localhost:3000 Referer: http://localhost:3000/

{ "code": "" }

Error details are as below

Error: Invalid algorithm
   at Module.validateJWT (file:///Users/techex/experiments/gitquid/gitquid/app/node_modules/oslo/dist/jwt/index.js:55:15)
   at validateJWT (/Users/techex/experiments/gitquid/gitquid/app/.wasp/out/sdk/wasp/auth/jwt.ts:17:33)
   at Object.verifyToken (/Users/techex/experiments/gitquid/gitquid/app/.wasp/out/sdk/wasp/server/auth/oauth/oneTimeCode.ts:23:12)
   at <anonymous> (/Users/techex/experiments/gitquid/gitquid/app/.wasp/out/server/src/auth/providers/oauth/oneTimeCode.ts:23:47)
   at <anonymous> (/Users/techex/experiments/gitquid/gitquid/app/.wasp/out/sdk/wasp/server/utils.ts:26:11)
   at Layer.handle [as handle_request] (/Users/techex/experiments/gitquid/gitquid/app/.wasp/out/server/node_modules/express/lib/router/layer.js:95:5)
   at next (/Users/techex/experiments/gitquid/gitquid/app/.wasp/out/server/node_modules/express/lib/router/route.js:149:13)
   at Route.dispatch (/Users/techex/experiments/gitquid/gitquid/app/.wasp/out/server/node_modules/express/lib/router/route.js:119:3)
   at Layer.handle [as handle_request] (/Users/techex/experiments/gitquid/gitquid/app/.wasp/out/server/node_modules/express/lib/router/layer.js:95:5)
   at /Users/techex/experiments/gitquid/gitquid/app/.wasp/out/server/node_modules/express/lib/router/index.js:284:15

Not able to understand where it is going wrong?

yashomi-t3h commented 1 month ago

Seems the wasp-lang only supports HMAC algorithm. Google oauth returns only RSA based Id_tokens. Is there any way to get around this when using chrome extension?

infomiho commented 1 month ago

Related to: https://ptb.discord.com/channels/686873244791210014/1286743756594352228/1286743756594352228 continuing there.