我正在使用谷歌日历 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/