- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发一个 REST API,计划将其与 Web 和 IOS 应用程序一起使用。我打算让这个 API 在一段时间内保持私有(private)(私有(private)意味着我只希望我的 Web 应用程序和 ios 应用程序访问该 API)。
我已经了解了许多不同的身份验证方法,但我仍然很困惑为我的 API 选择适当的身份验证方法。
据我了解,oAuth2是为了允许用户使用其他服务提供商登录您的APP,以便您可以访问相应服务提供商的数据。我正在自己的 API 中访问数据,所以我相信这不适用于我?
所以,这就是我的想法:
1) 使用 HTTP 基本身份验证将用户/密码发送到服务器。
2) 服务器验证登录后,返回将在 x 小时后过期的访问 token 。这将允许我简单地存储 token 而不是用户/通行证凭据。
我在 Google 上搜索了这种技术,但没有真正找到有关此方法的任何信息,这让我相信这不是一个好方法,因为我可能会尝试重新发明某些东西?
我应该做什么?我正在寻找两条腿的 oAuth 吗?
最佳答案
OAuth 2.0 已成为保护 Web API 的首选协议(protocol)。它需要用户授权应用程序访问您的 Web API。
您希望您的应用程序是唯一可以访问某些 API 的应用程序。 OAuth 2.0 允许这样做。
在您的授权服务器中,实现 Authorization Code Grant需要客户端凭据(不是可选的)。确保只有您的应用程序(或配置的第一方应用程序列表)才能获取进行这些 API 调用所需的范围。只要您确实对客户端 secret 保密,您的应用程序将是唯一能够获得具有所需范围的访问 token 的应用程序。在 Web API 中,确保将范围授予用于调用 API 的访问 token 。
良好的授权服务器,例如The Identity Hub ,将允许您做到这一点。
请勿使用Resource Owner Password Credentials Grant 。正如规范所述:
The credentials should only be used when there is a highdegree of trust between the resource owner and the client (e.g., theclient is part of the device operating system or a highly privilegedapplication), and when other authorization grant types are notavailable (such as an authorization code).
这是重复的later on :
The authorization server should take special care whenenabling this grant type and only allow it when other flows are notviable.
如果密码凭据授予可用,任何应用程序都可以通过询问用户的用户 ID 和密码来获取 token 。这正是您不想要的。
规范is very clear关于使用密码固有的问题:
In the traditional client-server authentication model, the clientrequests an access-restricted resource (protected resource) on theserver by authenticating with the server using the resource owner'scredentials. In order to provide third-party applications access torestricted resources, the resource owner shares its credentials withthe third party. This creates several problems and limitations
OAuth 2.0 专门设计用于克服使用密码的一些问题:
OAuth addresses these issues by introducing an authorization layerand separating the role of the client from that of the resourceowner. In OAuth, the client requests access to resources controlledby the resource owner and hosted by the resource server, and isissued a different set of credentials than those of the resourceowner.
此外,如果您的 API 想要了解用户(除了了解客户端应用程序之外),则不可能滥用资源所有者密码凭证授予来验证客户端(即应用程序)而不是资源所有者(即用户) ),按照 Florent Morselli 的建议。
关于security - HTTP 基本身份验证 + 访问 token ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26502495/
请帮助我的建议。 我需要通过 xml 文件中的某个变量在我的应用程序上禁用/启用 spring 安全性。 我的 spring-security.xml 文件
我做了很多研究,对我来说一切看起来都是正确的......但我无法让它发挥作用!有人有什么想法吗? 无论我做什么,相关映射仍然对任何人公开(匿名或登录,无论他们具有什么角色)。 理想情况下,我希望所有请
我们正在考虑为我们网站的一部分启用 SSL,但某些页面包含来自第三方供应商(如 Google AdSense)的广告。 我认为这会给我们的用户带来一个恼人的问题,因为他们在查看带有广告的页面时会看到类
我正在开发一个休息服务,它将通过浏览器提供 浏览器单页应用程序和移动应用程序。目前我的服务正在运行 根本没有 Spring 。 oauth2 客户端是在过滤器内部实现的,所以可以说是“手动”。 我正在
我正在为我公司的网站添加 Content-Security-Policy-Report-Only 标题。在我研究它时,我发现一些页面已经设置了 Content-Security-Policy head
在 XML 配置中,我可以使用 security 命名空间来启用对安全性的支持,例如: 我尝试使用没有 XML 的 Spring,只有 @Configuration 类。与上述 XM
我正在使用 Spring Security 3.0.2,但找不到从数据库加载匿名用户角色的方法(我有动态角色,可以将角色分配给每个人)。 我尝试使用自定义的anonymousAuthenticatio
我有那个代码。但是当我在浏览器中进入 app_dev.php/login浏览器说:该页面进行了太多重定向 安全.yml安全: 编码器: Symfony\Component\Security\Core\
我正在使用SSH Secure Shell客户端,这是一个连接服务器的好工具。 但是,我想知道是否可以记录通过SSH Secure Shell客户端运行的程序中所有即将出现的消息。例如:./ test
我有那个代码。但是当我在浏览器中进入 app_dev.php/login浏览器说:该页面进行了太多重定向 安全.yml安全: 编码器: Symfony\Component\Security\Core\
如何为表单例份验证提供程序设置 success_handler(和 failure_handler)? Silex 使用此配置忽略我: register(new Silex\Provider\Secu
新手问题...我已成功实现自定义处理程序和服务(自定义用户详细信息服务、身份验证成功、身份验证失败)并且一切正常。我现在还实现了如果 3 次并发身份验证失败将锁定帐户(一定时间)的功能。 我现在继续处
我正在使用 Spring security java 配置,我想知道一种实现多个 url 注销的方法。即 logout().logoutRequestMatcher(new AntPathReques
我正在为我的 SP 使用 Spring Security SAML 扩展。用户通过 IDP 身份验证后,SP 使用某种方法允许后续调用不必通过 IDP 重新进行身份验证。这是如何在 Spring Se
spring security 有没有办法防止下面的最后一点?我正在使用 3.0.5 - 用户登录我的网站 - 用户转到网站中的任何页面并单击注销 -注销链接使用户 session 无效并将它们发送到
要么我迟到了,要么我做错了什么。我正在使用 Visual Studio 2013,但是我试图使用 Membership 类,using System.Web.Security;我的程序集中不存在命名空
我有一个具有依赖性的oauth2客户端spring-boot应用程序: - Spring 靴1.2.0.RC1 -spring-security-oauth2 2.0.4.RELEASE - Spri
我想在控制台应用程序中生成 HashPasswordForStoringInConfigFile。 它是在 Web 应用程序中使用以下类完成的 System.Web.Security.FormsAut
我需要有多个 PRE_AUTH Spring 安全过滤器。特别是我需要使用 PRE_AUTH除了配置为 PRE_AUTH 的两个过滤器之外的过滤器在 Spring Security 3.0 的 SAM
我猜这里没有答案,但我想知道是否有办法创建这样的自定义注释: @Documented @Inherited @Retention(RetentionPolicy.RUNTIME) @Target({E
我是一名优秀的程序员,十分优秀!