我可以使用HTTP基本身份验证,以正宗的两个应用程序和用户的Web API? [英] Can I use HTTP basic authentication to authentic both the apps and users in web API?

查看:141
本文介绍了我可以使用HTTP基本身份验证,以正宗的两个应用程序和用户的Web API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我提供了一组公共Web API的第三方应用程序(客户端)使用的。我想跟踪这些客户如何使用我的API,所以我需要为这些客户令牌。由于同一时间,我需要真正的用户进行身份验证,不同的用户可以看到同样的资源不同的重新presentations。我知道的OAuth2可以解决我的问题,但它是复杂的。我使用HTTPS +基本身份验证对用户和应用程序中都preFER,所以我会在客户端和真实用户的HTTP头中使用不同的属性。它是适当的方式?

I provide a set of public web APIs for third party apps (clients) to use. I want to track how these clients use my APIs, so I need to generate tokens for these clients. As the same time, I need to authenticate real users, and different users can see different representations of the same resources. I know OAuth2 can solve my problem, but it is complicated. I prefer using HTTPs + basic authentication for both the user and the application, so I will use different properties in the HTTP header for client and real user. Is it appropriate way?

推荐答案

一般来说,因为它需要凭据(用户名/密码)的所有请求,这是不是你想要的基本身份验证不会做的工作。

Generally speaking, Basic Authentication does not do the job because it requires credentials (username/password) for all the requests and this is not what you want.

首先我们来分析一下您的要求:

Firstly let's analyze your requirements:


  • 您希望最终用户能够访问你的服务

  • 您想授权的第三方应用程序能够访问其他最终用户的数据(与用户的批准)

  • 您不希望第三方应用程序得到其他最终用户的凭据

因此​​,我们可以总结出理想的工作流程为:

So we could summarize the ideal workflow as:


  1. 最终用户运行第三方应用程序,并说:我想给你访问服务

  2. 的第三方应用程序变成你的服务的API,并说:我想访问该用户的数据

  3. 您服务展示了一个访问赠款页,同时说:你要授予此应用程序来访问下列数据你? (重要提示:此访问授权服务是由你,而不是第三方应用程序提供)

  4. 最终用户同意,并输入用户名/密码(最终用户需要确定此访问赠款网页是由你!),并授予

  5. 您的访问授权页面生成令牌和第三方使用该令牌通过访问您的数据:

  6. 的第三方应用程序发送一个请求到你的服务,并说:这是为最终用户授权令牌,请给我的数据

  7. 您的验证服务,同时第三方和最终用户的令牌,并作出回应。

  8. 的第三方应用程序可以做更多的要求,只要令牌没有过期。

,最终用户只有输入1时的用户名/密码,所以基本身份验证不能满足您的要求。

Based on above workflow, end user have only input 1 time username/password, so Basic Authentication does not fulfill your requirement.

其实,你的要求是基于令牌身份验证(肯定需要令牌到期机制):第三方只得到最终用户的授权令牌而不是凭据。

Actually, your requirement is Token Based Authentication (for sure you need token expiration mechanism): The 3rd party only gets end users' authorization token rather than credentials.

要做到这一点,没有OAuth的,你需要实现令牌生成,验证和到期机制。

To do this, without OAuth, you need implement token generation, validation and expiration mechanism.

和肯定的,你可以把无论是在依赖于你的preference或设计理念HTTP头或URL的标记。

And for sure you could put those tokens either in HTTP header or URL which depends on your preference or design philosophy.

希望这有助于!

这篇关于我可以使用HTTP基本身份验证,以正宗的两个应用程序和用户的Web API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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