英文:
Aquiring a short-lived ID token for Cloud Run in React JS using google-auth-library
问题
I have a React JS project, that lets users log in via my own Keycloak-based ID provider, returning a JWT token in case of successful authentication.
I'd like to use this token to acquire a short-lived ID token from Google Cloud to invoke a Cloud Run endpoint.
All GCP configuration has been set up correctly since I can get this token if I invoke the proper endpoints by hand, but I'd like to automate it from my React app. AFAIK the google-auth-library
has the functionality implemented that lets me get this token, but when I npm i google-auth-library
it in my project and start the app, I get a plethora of errors akin to this:
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "util": require.resolve("util/") }'
- install 'util'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "util": false }
Is there a way for me to prevent these errors from happening? I already tried react-app-rewrite
without much success.
React version: 18.2.0
google-auth-library version: 8.7.0
英文:
I have a React JS project, that lets users log in via my own Keycloak-based ID provider, returning a JWT token in case of successful authentication.
I'd like to use this token to acquire a short-lived ID token from Google Cloud to invoke a Cloud Run endpoint.
All GCP configuration has been set up correctly since I can get this token if I invoke the proper endpoints by hand, but I'd like to automate it from my React app. AFAIK the google-auth-library
has the functionality implemented that lets me get this token, but when I npm i google-auth-library
it in my project and start the app, I get a plethora of errors akin to this:
BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "util": require.resolve("util/") }'
- install 'util'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "util": false }
Is there a way for me to prevent these errors from happening? I already tried react-app-rewrite
without much success.
React version: 18.2.0
google-auth-library version: 8.7.0
答案1
得分: 1
你遇到错误的原因是 google-auth-library
是一个 Node.js 库,而不是 React.js 库。
在 React.js 前端中不应使用 google-auth-library
,因为它会带来安全风险。
你可以查找并使用与 google-auth-library
中要使用的相同功能相对应的 API 调用。
或者创建一个 Node.js 服务器,用于在前端执行这些操作。
英文:
You are facing the error cause google-auth-library
is a node.js library and not a react js library.
You should not use google-auth-library
in React.js frontend cause it'll pose a security threat.
You can find and use API calls for the same function you are going to use in the google-auth-library.
Or else create a node js server which does these things for your frontend.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论