javascript - 在代码中包含客户端 ID 和客户端密码是否存在安全风险?

标签 javascript google-api google-oauth google-api-js-client

我正在使用谷歌日历 API 将事件添加到日历中。我想知道这是否会是安全问题,因为我在 JS 中使用客户端 ID 和 API 代码,这些代码可能会暴露给使用该应用程序的人? 另外,如果是这种情况,如何保护这些 key ?

PS- 我正在关注的文档- https://developers.google.com/calendar/quickstart/js

最佳答案

您注意到重定向 uri 了吗?重定向 uri 告诉 googles auth 服务器返回访问 token 的位置。

即使我获取了您的客户 ID 和客户密码。我无法使用它,因为服务器会将访问 token 发送到重定向 uri 到您的服务器。

这就是为什么您不应该将 localhost 设置为重定向 uri。 😉

RFC oauth2 redirection endpoint

After completing its interaction with the resource owner, the authorization server directs the resource owner's user-agent back to the client. The authorization server redirects the user-agent to the client's redirection endpoint previously established with the authorization server during the client registration process or when making the authorization request.

也就是说,您应该尽量将这些 key 保密,您不应该共享它们或将它们添加到开源项目中。然而,像 javascript 这样的客户端应用程序是一个灰色区域。

关于javascript - 在代码中包含客户端 ID 和客户端密码是否存在安全风险?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66207649/

相关文章:

angularjs - 使用 Google API 将变量从 AngularJS 服务传递到 Controller ?

oauth-2.0 - Force.com OAuth 2.0 JWT 到 Google 服务帐户融合表 API 400 错误请求 Invalid_Grant

ios - Google Calendar API 事件插入总是返回 404 “not found” 错误 iOS

javascript - 仅显示下拉 ajaxToolkit 中匹配的搜索模式项 :ListSearchExtender

Javascript - 当左侧的 div 为 100% 时,如何获得警报?

node.js - 无法访问Google日历API的googleapis auth.OAuth2

google-api - GoogleUser.getAuthResponse()不包含access_token

javascript - 在 1 行上有两个元素,但保持不同的高度

javascript - JQuery 操作 Div 集的子级

php - 从 Google OAuth 2.0 PHP API 获取用户信息