json - 人们如何处理 RESTful api 的身份验证(技术不可知)

标签 json api authentication rest

我正在考虑构建一些移动应用程序。因此,这些应用程序将通过 JSON 和 REST(例如放置、发布等)与我的服务器“对话”。

如果我想确保客户端电话应用程序正在尝试执行需要某些“许可”的操作,人们该如何处理?

例如:

Our website sells things -> tv's, car's, dresses, etc. The api will allow people to browse the shop and purchase items. To buy, you need to be 'logged in'. I need to make sure that the person who is using their mobile phone, is really them.



如何才能做到这一点?

我看过 twitter 如何使用他们的 OAuth .. 看起来他们在请求头中有很多值?如果是这样(而且我有点喜欢这种方法),我是否可以使用另一个 3rd 方作为网站来存储用户名/密码(例如 twitter 或 Facebook 是 OAuth 提供者)..我所做的只是以某种方式检索自定义 header 数据 .. 并确保它存在于我的数据库中 .. 否则 .. 让他们向他们的 OAuth 提供者进行身份验证?

或者还有其他方法吗?

附注。我真的不喜欢拥有 API key 的想法 - 我觉得它很容易交给另一个人使用(我们不能冒险)。

最佳答案

Our website sells things -> tv's, car's, dresses, etc. The api will allow people to browse the shop and purchase items. To buy, you need to be 'logged in'. I need to make sure that the person who is using their mobile phone, is really them.



如果这确实是一个要求,那么您需要在系统中存储用户身份。最流行的身份跟踪形式是通过用户名和密码。

I've had a look at how twitter does it with their OAuth .. and it looks like they have a number of values in a REQUEST HEADER? If so (and I sorta like this approach), is it possible that I can use another 3rd party as the website to store the username / password (eg. twitter or Facebook are the OAuth providers) .. and all I do is somehow retrieve the custom header data .. and make sure it exists in my db .. else .. get them to authenticate with their OAuth provider?



您在这里混淆了两种不同的技术,OpenIDOAuth (别难过,很多人都被这件事绊倒了)。 OpenID 允许您将身份跟踪和身份验证推迟到提供者,然后在您的应用程序中接受这些身份,作为接受者或依赖方。另一方面,OAuth 允许应用程序(消费者)访问属于另一个应用程序或系统的用户数据,而不会损害其他应用程序的核心安全性。如果您希望第三方开发人员代表您的用户访问您的 API(这不是您已声明要执行的操作),您将支持 OAuth。

对于您陈述的要求,您绝对可以考虑将 Open ID 集成到您的应用程序中。有许多库可用于集成,但由于您要求的是不可知的答案,因此我不会列出其中任何一个。

Or is there another way?



当然。您可以在系统中存储用户 ID 并使用 basicdigest身份验证以保护您的 API。基本身份验证在您的请求中只需要一个(易于计算的)附加 header :
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==

如果您使用基本身份验证或摘要式身份验证,请确保您的 API 端点受到 SSL 保护,否则用户凭据可以通过无线方式轻松嗅探。您还可以放弃用户身份识别,而是在结账时通过信用卡信息有效地验证用户身份,但这是一种判断力。

关于json - 人们如何处理 RESTful api 的身份验证(技术不可知),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9551080/

相关文章:

authentication - 如何存储 google api (OAuth 2) 权限?

flash - 使用 Joomla 和 Flash 进行单点登录

java - java.lang.String 类型的 value 数据无法转换为 JSONObject @ java android

具有空值的 json_array_elements

json - 将 json 读入 R

javascript - 如何修复 localhost 中的 react cors 错误?

sql - 如何从 json 中进行文本查询

REST - 删除后使用 HTTP 缓存获取集合

java - Face++ 比较 API

java - Minecraft 启动器登录代码