Php 在Symfony中,如何授权用户使用密码/用户名一次,然后使用访问/刷新令牌?
我一直在尝试使用Symfony为应用程序构建一个安全层。我有一个web服务,我可以授权用户使用oAuth2Php 在Symfony中,如何授权用户使用密码/用户名一次,然后使用访问/刷新令牌?,php,security,symfony,authentication,oauth-2.0,Php,Security,Symfony,Authentication,Oauth 2.0,我一直在尝试使用Symfony为应用程序构建一个安全层。我有一个web服务,我可以授权用户使用oAuth2资源所有者密码凭据授予——将用户名/密码交换为承载令牌,如下所示: { "token_type": "bearer", "access_token": "16fcd735-7063-42c2-83cd-448f2e9c4396", "refresh_token": "bc3d5d57-a5ef-445b-ac28-714c3bdfda46", "expires_in": 43
资源所有者密码凭据授予
——将用户名/密码交换为承载令牌,如下所示:
{
"token_type": "bearer",
"access_token": "16fcd735-7063-42c2-83cd-448f2e9c4396",
"refresh_token": "bc3d5d57-a5ef-445b-ac28-714c3bdfda46",
"expires_in": 43197,
"scope": "",
"user_id": "",
"username": ""
"user_roles": {
"ROLE_ADMIN": "ACTIVE"
},
}
一旦获得授权,我可以使用access_令牌访问其他API端点
我几乎没有涉足Symfony安全性的经验,因此在实现这一点时,我遇到了一个难题。我在Symfony 2.4中发现了新功能:轻松定制安全功能,如何使用API密钥验证用户,如何创建自定义身份验证提供程序,而且一切看起来都相当简单,但就我的一生而言,我无法理解如何以及在什么时候从
UsernamePasswordToken
切换到mycustomoauthttoken
我是否设置了第二个防火墙,仅允许使用UsernamePasswordToken的用户通过,如下所示:
另外,我是将API令牌数据存储在自定义令牌中,还是作为用户实体的一部分
非常感谢您在这方面的任何意见
public function createToken(Request $request, $providerKey)
{
// set the only URL where we should look for auth information
// and only return the token if we're at that URL
$targetUrl = '/login/check';
if (!$this->httpUtils->checkRequestPath($request, $targetUrl)) {
return;
}
[...]