简体   繁体   English

Symfony 2 RESTful API OAuth2

[英]Symfony 2 RESTful API OAuth2

I have 2 app:我有 2 个应用程序:

1 APP - main app (CMR) 2 APP - website 1 APP - 主应用程序 (CMR) 2 APP - 网站

The main aim is connect to 2 APP from 1 APP using OAuth2;主要目的是使用 OAuth2 从 1 个 APP 连接到 2 个 APP;

1 APP is implemented FOSOAuthServerBundle, but not exist no one oauth2 clients. 1个APP实现了FOSOAuthServerBundle,但不存在没有oauth2客户端。

The problem is that I can't generate oauth2 clients, because users know only username/password credentials.问题是我无法生成 oauth2 客户端,因为用户只知道用户名/密码凭据。

In first step users submit login forms - then in some way I need from user credentials generate tokens.在第一步用户提交登录表单 - 然后以某种方式我需要从用户凭据生成令牌。

Could I securely generate oauth2 clients with same id & secret as user username/password ?我可以安全地生成与用户用户名/密码具有相同 ID 和密码的 oauth2 客户端吗?

The users doesn't need to know the client_id and client_secret.用户不需要知道 client_id 和 client_secret。 Actually is not safe at all for them to be known by anyone else, except the APP 2. The client credentials (client_id, client_secret) are generated in the auth server.实际上,除了 APP 2 之外,其他任何人都知道它们根本不安全。客户端凭据(client_id、client_secret)是在身份验证服务器中生成的。 Then the APP 2 devs get this client credentials and stores them somewhere where only the APP 2 has access to them (like the app 2 config files, or the app 2 db).然后 APP 2 开发人员获取此客户端凭据并将它们存储在只有 APP 2 可以访问它们的地方(如 app 2 配置文件或 app 2 db)。 After this is done, when a user wants to login, he only provides the username and password, app 2 wraps them in an API call to the token API of the auth server, with the grant type 'password' and wanted scopes.完成后,当用户想要登录时,他只提供用户名和密码,应用程序 2 将它们包装在对身份验证服务器的令牌 API 的 API 调用中,授予类型为“密码”和想要的范围。

But this only scratches the surface of auth2.但这只是触及了 auth2 的表面。 If you add a third app to your network, and you want A2 and A3 to communicate securely using token generated by A1, then you will need a introspect API in A1, or even using signed JWT openId.如果您将第三个应用程序添加到您的网络,并且您希望 A2 和 A3 使用 A1 生成的令牌安全地通信,那么您将需要 A1 中的自省 API,甚至使用签名的 JWT openId。

Long story short, FOSOAuthServerBundle is a good start but in the long run you will need to put in a lot of work.长话短说,FOSOAuthServerBundle 是一个好的开始,但从长远来看,您需要投入大量工作。 Here is some material to guide you.这里有一些材料可以指导您。

Auth2 rfc: https://tools.ietf.org/html/rfc6749 Auth2 RFC: https ://tools.ietf.org/html/rfc6749

Token introspect rfc: https://tools.ietf.org/search/rfc7662令牌自省 rfc: https : //tools.ietf.org/search/rfc7662

sign JWT: https://jwt.io签署 JWT: https : //jwt.io

Also look into openId, RBAC, ACL.还要查看 openId、RBAC、ACL。 This will also come in handy at some point.这在某些时候也会派上用场。

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

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