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

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

问题描述

我有两个单独的Web应用程序:

I have two separate web apps:


  • 数据库API

  • 和基本的Web的客户端(瓶),还有一些JS- code(KnockouJS)交互式
    功能,如在即时'过滤产品,购物车等。

要实现通过API交互的答案我使用用户的浏览器中运行的JavaScript请求。我想控制访问的API,并给它只能与授权网络应用程序,例如,我自己的客户端JS- code。

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- code可以访问一个秘密,比互联网上的任何人都有访问,对吧?

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应用程序被所谓的 公共客户中的OAuth 2.0。它基本上意味着他们不能保守秘密,因此,你的不能做客户端(应用程序)的授权。

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:基于用户代理客户端(APP)授权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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