简体   繁体   English

用户和应用程序的REST API身份验证

[英]REST API Authentication both User and Applicatoin

I'm developing a BaaS solution that provides developers some REST APIs for their applications. 我正在开发一个BaaS解决方案,该解决方案为开发人员的应用程序提供了一些REST API。 In addition of SSL, I want to secure the REST API authenticating both application (token?) and client (user and password). 除了SSL,我想保护REST API,以同时验证应用程序(令牌?)和客户端(用户名和密码)。

I was thinking on Basic Authentication for clients and a token for application authentication, however I can't think on how a simple UUID token, given to the application developer on registration phase, can secure the REST API and authenticate the application. 我当时在考虑客户端的基本身份验证和应用程序身份验证的令牌,但是我无法考虑在注册阶段提供给应用程序开发人员的简单UUID令牌如何保护REST API并验证应用程序。

Also I read about OAuth, however I think it doesn't fit as a solution to the authentication mechanism. 我还阅读了有关OAuth的信息,但是我认为它不适合作为身份验证机制的解决方案。

How can I achive this in the right way? 我怎样才能正确地做到这一点?

Thanks! 谢谢!

It does seem to be a good (and common) approach to use "basic authentication" for user authentication and then "token authentication" for accessing resources (all over SSL). 将“基本身份验证”用于用户身份验证,然后将“令牌身份验证”用于访问资源(全部通过SSL)似乎确实是一种好方法(并且很常见)。 Basically to support this you do user authentication using "basic authentication" (username/password) over SSL, and based on positive "authentication" the user is given a "bearer token" (or authentication token). 基本上要为此提供支持,您可以通过SSL使用“基本身份验证”(用户名/密码)进行用户身份验证,并根据肯定的“身份验证”为用户分配一个“承载者令牌”(或身份验证令牌)。 The user credentials are normally stored (hashed and salted) in a DB, like the authentication token. 用户凭据通常与身份验证令牌一样存储(散列和加盐)在DB中。 Based on the retrieved token the user can access the API resources (also over SSL to grant maximum security of channel). 基于检索到的令牌,用户可以访问API资源(也可以通过SSL来授予最大的通道安全性)。 From time to time (or per device) you can change the token. 您可以不时(或按设备)更改令牌。

Not sure which technology you are using to develop your RESTful web service. 不知道您正在使用哪种技术来开发RESTful Web服务。 In Java I have been using Apache Shiro ( http://shiro.apache.org/ ), which allows to support all these activities (basic authentication, token-based authentication, encryption of data (hashing + salting) to store in DB, etc. - take a look on another post I wrote about how to set up this approach in shiro: https://stackoverflow.com/a/17950339/1029673 ). 在Java中,我一直在使用Apache Shiro( http://shiro.apache.org/ ),它可以支持所有这些活动(基本身份验证,基于令牌的身份验证,数据加密(哈希+盐化)以存储在数据库中,等-看看我写的另一篇关于如何在shiro中设置这种方法的文章: https : //stackoverflow.com/a/17950339/1029673 )。

HTH. HTH。

Finally I came up with OAuth 2.0 Resource Owner Password Flow which fits in my security schema. 最后,我想出了适合我的安全模式的OAuth 2.0资源所有者密码流。

Thanks! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM