REST API:基于用户代理的客户端(应用)授权 [英] REST API: user-agent-based client (app) authorization

查看:24
本文介绍了REST API:基于用户代理的客户端(应用)授权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个独立的网络应用程序:

I have two separate web apps:

  • 数据库 API
  • 和基本的 web 客户端 (Flask) 以及一些用于交互的 JS 代码 (Knockout.js)诸如即时"过滤产品、购物车等功能.

为了通过 API 实现交互式答案,我使用了在用户浏览器中运行的 JavaScript 请求.我想控制对 API 的访问并仅将其提供给授权的网络应用程序,例如,我自己的客户端 JS 代码.

To implement interactive answers through API I use JavaScript requests running in a user's browser. I want to control access to API and give it only to authorized web-apps, for example, my own client JS-code.

我了解了 HMAC 和 Oauth.关键点:例如,服务器和客户端共享用于生成 HMAC 的相同密钥.

I read about HMAC and Oauth. The key point: the server and the client share the same secret which is used to generate a HMAC, for example.

但是我应该如何使用机密在用户浏览器中生成 HMAC,而不是将机密暴露给其他人?据我所知,如果我的 JS 代码可以访问某个秘密,那么互联网上的任何人都可以访问,对吗?

But how should I generate a HMAC inside a user's browser using a secret and not exposing the secret to others? As I understand, if my JS-code has access to a secret, than anybody on the internet has that access, right?

推荐答案

JavaScript 应用程序被称为 '公共客户端'.这基本上意味着他们无法保密,因此您无法进行客户端(应用程序)授权.

JavaScript applications are what are called 'public clients' in OAuth 2.0. It basically means they cannot keep secrets and therefore you cannot do client (application) authorization.

因此,如果您使用 JavaScript 应用程序与 API 通信,则需要进行用户身份验证并授予用户对 API 的访问权限.或者切换到服务器端应用程序来访问您的 API.

So, if you are using a JavaScript application to talk to your API, you'll need to do user authentication and give users access to your API. Or switch to a server side application to access your API.

这篇关于REST API:基于用户代理的客户端(应用)授权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆