man*_*oon 5 php oauth symfony fosuserbundle fosoauthserverbundle
目前我的项目运作良好.我使用FOSUserBundle来管理我的用户.现在,我想实现OAuth,所以我使用的是FOSOAuthServerBundle.大多数开发人员推荐使用此捆绑包来实现OAuth.
我按照FOSOAuthServerBundle的文档.通常,我必须在我的security.yml中添加更多信息,但我不确切知道我要做什么......
这是我的security.yml:
security:
encoders:
Symfony\Component\Security\Core\User\User: plaintext
Moodress\Bundle\UserBundle\Entity\User: sha512
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
providers:
main:
id: fos_user.user_provider.username
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
oauth_token:
pattern: ^/oauth/v2/token
security: false
oauth_authorize:
pattern: ^/oauth/v2/auth
main:
pattern: ^/
fos_oauth: true
stateless: true
anonymous: true
Run Code Online (Sandbox Code Playgroud)
我想有一些信息可以添加到防火墙中吗?
我真的不知道如何使用FOSUserBundle制作FOSOAuthServerBundle.之前,只使用FOSUserBundle,我使用了登录表单和FOSUserBundle的登录检查.既然我已经完成了FOSOAuthServerBundle的所有基本配置,那我接下来要做什么?我应该使用哪种表格?哪个登录检查?令牌是由FOSOAuthServerBundle自动创建的?在文档中,它们展示了如何创建客户端...我应该在我的项目中添加此代码吗?如果是的话...在哪里?:/
我在网上找到了这篇文章:http://blog.logicexception.com/2012/04/securing-syfmony2-rest-service-wiith.html
我试图实现这个,但我不相信我们需要添加所有这些文件才能使它工作......
如果有人知道如何使用FOSUserBundle制作FOSOAuthServerBundle,那将非常有用.
小智 7
我刚安装了这个捆绑包并开始玩它.
我想您需要先了解OAuth身份验证的工作原理.
这样您就会明白FOSUserBundle机制与OAuth不完全相同.
您的链接是正确设置捆绑包的最佳信息.
我正在使用MongoDB来存储所有4个必需的文档:Client,AuthCode,RefreshToken和AccessToken
称为"创建新客户端"的步骤基本上是用于OAuth的FOSUserBundle的"注册"过程.
OAuth将使用客户端授予访问权限.
OAuth的主要思想是保护API,因此我建议您将配置切换为匿名:false
然后你会看到这样的信息:
{"error":"access_denied","error_description":"OAuth2 authentication required"}
当你打电话给你的API
OAuth的想法是获取一个访问令牌来调用您的API.阅读本文:http://blog.tankist.de/blog/2013/07/16/oauth2-explained-part-1-principles-and-terminology/
这是需要遵循OAuth身份验证过程的时间.
有5种基本方法可供使用:
const GRANT_TYPE_AUTH_CODE = 'authorization_code';
const GRANT_TYPE_IMPLICIT = 'token';
const GRANT_TYPE_USER_CREDENTIALS = 'password';
const GRANT_TYPE_CLIENT_CREDENTIALS = 'client_credentials';
const GRANT_TYPE_REFRESH_TOKEN = 'refresh_token';
Run Code Online (Sandbox Code Playgroud)
要了解每个,请查找有关OAuth RFC的更多文档.
它们中的每一个对应于特定的调用:/ oauth/v2/token?client_id = [CLIENT_ID]&response_type = code&redirect_uri = URL&grant_type = token
Cf:https://github.com/FriendsOfSymfony/oauth2-php/blob/master/lib/OAuth2/OAuth2.php#L182
"测试时间"部分介绍了如何使用OAuth.
我还在努力.
希望能帮助到你.
此链接还指示如何使用FOSUserBundle用户和UserManager可能使用密码grant_type:如果您正在验证用户,请不要忘记设置用户提供程序.
以下是使用FOSUserBundle用户提供程序的示例:https: //github.com/FriendsOfSymfony/FOSOAuthServerBundle/blob/master/Resources/doc/index.md
# app/config/config.yml
fos_oauth_server:
...
service:
user_provider: fos_user.user_manager
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8877 次 |
最近记录: |