oAuth2使用并行登录类型获取访问和刷新令牌

时间:2019-02-19 08:53:43

标签: php symfony oauth-2.0 fosuserbundle access-token

我对Symfony和oauth身份验证不是很自信...

我们有一个具有标准登录名的Web应用程序,该应用程序可以按预期运行。 现在,我们正在尝试为使用智能卡的用户提供一种并行身份验证方式。 我能够读取智能卡,但无法使用oauth请求来检索访问权限并刷新令牌。

我的想法是使用这些数据进行身份验证(均保存在用户表中):

  • 智能卡ID(例如:2221)。这是从智能卡读取的。
  • 智能卡签名(通过串联智能卡的名称,姓氏和其他数据生成)。我的想法是到md5()然后是这个串联的字符串。此签名也保存在用户表中。

那么,如何使用此数据检索有效的访问并刷新令牌?

在这种情况下正确的grant_type是什么,还需要其他什么参数?

这是我的代码:

    $token = new UsernamePasswordToken($user, $smartCardSignature, 'main', $user->getRoles());

    $user = $token->getUser();

    $arrayOauthCredentials = array(
        "client_id"     => $client_id,
        "client_secret" => $client_secret,
        "grant_type"    => "password",
        "username"      => // ?????
        "password"      => // ?????
    );

    $oAuth2GetAccessTokenReq = $this->oAuth2HttpClient->createRequest("POST", $this->getOAuth2Endpoint(self::TOKEN_ACTION), null, $arrayOauthCredentials);
    $oAuth2Response =  $this->oAuth2HttpClient->send($oAuth2GetAccessTokenReq);
    $oAuth2 = json_decode($oAuth2Response->getBody(true));
    $accessToken  = $oAuth2->access_token;
    $refreshToken = $oAuth2->refresh_token;

    $session = $request->getSession();
    if ($session->has("r_t"))
        $session->remove("r_t");

    $session->set("r_t", $refreshToken);

    $user->setOAuth2Token($accessToken);
    $this->em->persist($user);
    $this->em->flush($user);

    $this->get('security.token_storage')->setToken($token);

谢谢大家

0 个答案:

没有答案
相关问题