oauth - Can Oauth be used securely from the client side for a back-end service?
问题描述
I have a web app (C# / Javascript) where I want to call a back-end service that I own. I want to secure that service so only my app(s) can call it. Seems like if I use Oauth on the client side, the secret is exposed? All the docs I read about Oauth give solutions when the user of the app owns the resource, not when the app itself owns it. I was looking at how google apis work, and the JavaScript libraries seem to expose the key on the client side, no?
解决方案
是的,您可以使用 OAuth 完成此操作,但您如何执行此操作取决于如何组织通过后端服务访问的数据的详细信息。如果数据实际上是特定于用户的,那么您的用户确实是资源所有者。在这种情况下,您将使用典型的授权代码授予。使用此授权类型,您可以向 OAuth 身份验证服务器注册客户端并接收 client_id 和 client_secret。client_id 确实在浏览器中公开,但 client_secret 位于您的 Web 应用程序服务器中并且永远不会公开。它仅通过反向通道(非浏览器)请求发送到您的身份验证服务器。这里的主要内容是只有您自己的客户端 Web 应用程序会被注册并接收 client_id/client_secret。您只需要不提供任何公共注册端点,因此其他客户端无法注册。使用这种授权类型,
另一方面,如果您在后端服务上访问的数据不是特定于用户的,那么您可以使用 OAuth 客户端凭据授权。使用这种授权类型,您可以像以前一样注册客户端并接收 client_id 和 client_secret。该密钥安全地存储在您的 Web 应用服务器上,并且仅在反向通道请求中传递。您将避免允许任何其他客户注册。然后,您的 Web 应用程序可以获得对后端服务的授权,甚至不需要浏览器中的任何用户授权。
推荐阅读
- java - 原生 Android Inapp 购买 在哪里配置 Base64 编码的 RSA 许可证密钥?
- angular - “AngularFireObject<{}>”类型上不存在属性“管道”
- uwp - 为什么 StorageFile.GetFilesAsync() 在 dll 中崩溃?
- android - 如何使用 EditText 在片段和活动之间传递信息?
- windows - 如何修复命令提示符上的 Python“版本错误”?
- reactjs - 为每个 onChangeText 更新 TextInput 的 redux 状态是否是一个好习惯
- ios - 如何在 iPhone X 上获取 tabBar 的高度
- vim - 当 ^n 在 ssh 上的 vim 中时,突出显示行上的文本被隐藏
- python - Jupyter Notebook 中的 Tqdm 4.28.1“未找到 IntProgress。请更新 jupyter 和 ipywidgets。”
- canvas - P5.JS:将生成艺术(使用噪声())保存为设备上的图像并在 HTML 上重新上传它们