调用 RESTful api 时,将 api 令牌放入 http 请求 header 是否安全?例如:优步提醒 api

when calling RESTful api, is it safe to put api token in http request header? e.g.: Uber reminder api

您可以使用优步 RESTful api 发送提醒,例如"Movie at local AMC",优步应用用户。 api 文档是 here

POST /v1/reminders

但是你必须在 http 请求 header 中放置一个令牌(他们称之为服务器令牌)以进行身份​​验证。医生是 here

curl -H 'Authorization: Token YOUR_SERVER_TOKEN' \
'https://api.uber.com/v1/products?latitude=37.7759792&longitude=-122.41823'

用户可以使用 chrome 开发工具查看令牌。我的问题是:

将应用程序令牌放入从 front-end 发送的 http 请求 header 中是否安全?为什么? 我应该在服务器或浏览器中使用 Javascript 调用提醒吗?

虽然可以在 Developer Dashboard(下面的屏幕截图)中删除和生成新的服务器令牌,但您不应公开使用您的服务器令牌(例如通过前端的 JS 变量)。使用此令牌,其他人可以创建、检索、更新和删除提醒。

此外,服务器令牌可用于检索估计值(price & time) and Uber products on your behalf. This may sound insignificant but could impact your application's rate limiting(每小时 2000 次请求)。如果服务器令牌落入坏人之手,它可以有效地阻止您的应用程序与优步通信API 定期。

我强烈建议在服务器端实现它。