Fabric Digits oauth身份验证在PHP中


Fabric Digits oauth authentication in PHP

我有一个应用程序,可以使用Digits作为身份验证。客户端工作得很好,但我无法通过oAuth进行服务器用户身份验证。我的服务器是用Laravel开发的,所以它是PHP。我的端点在https下,所以一切都应该准备好进行调用。

我自己解决了!

以下是通过Digits O-Auth正确进行身份验证的代码。

进行身份验证的函数在AuthManager类中,我以这种方式调用:

$obj = AuthManager::verifyUser($request->header('X-Auth-Service-Provider'),$request->header("X-Verify-Credentials-Authorization"));

这是一个神奇的功能:

public static function verifyUser ($xAuthServiceProvider, $xVerifyCredentialsAuthorization)
{
    $curl = curl_init();
    curl_setopt($curl,CURLOPT_URL, $xAuthServiceProvider);
    curl_setopt($curl,CURLOPT_HTTPHEADER, array(
        'Content-length: 0',
        'Content-type: application/json',
        'Authorization: '.$xVerifyCredentialsAuthorization,
    ));
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    $content = curl_exec($curl);
    $info = curl_getinfo($curl);
    curl_close($curl);
    $obj = json_decode($content, true);
    return $obj;
}

如果你有任何问题,请毫不犹豫地写在这里!

使用有关如何从O-AUTH获取数据的示例函数进行编辑

public function authenticate (Request $request)
{
    $obj = AuthManager::verifyUser($request->header('X-Auth-Service-Provider'),$request->header("X-Verify-Credentials-Authorization"));
    if(isset($obj["errors"]))
    {
        return "error!";
    }
    $digits_token =  $obj["access_token"]["token"];
    $digitsId = $obj["id"];

    /*
        the variables above are returned by O-auth server-server authentication
    */
}