Php 自定义OAuth2用户数据库

Php 自定义OAuth2用户数据库,php,database,oauth,oauth-2.0,Php,Database,Oauth,Oauth 2.0,我目前正在我的网站上实现OAuth2,让用户登录到Android应用程序中。我想将默认的OAuth2用户数据库更改为我自己的用户数据库。不幸的是,我不知道怎么做。重写类和不更改核心库中的代码应该是可能的,但是如何做到呢 这是我的server.php文件中的内容: // Autoloading (composer is preferred, but for this example let's just do this) require_once('/src/OAuth2/Autoloader.p

我目前正在我的网站上实现OAuth2,让用户登录到Android应用程序中。我想将默认的OAuth2用户数据库更改为我自己的用户数据库。不幸的是,我不知道怎么做。重写类和不更改核心库中的代码应该是可能的,但是如何做到呢

这是我的
server.php
文件中的内容:

// Autoloading (composer is preferred, but for this example let's just do this)
require_once('/src/OAuth2/Autoloader.php');
OAuth2\Autoloader::register();

$storage = new OAuth2\Storage\Pdo(array('dsn' => 'mysql:host=xxxx;dbname=xxxx', 'username' => 'xxxx', 'password' => 'xxxx'));

// Pass a storage object or array of storage objects to the OAuth2 server class
$server = new OAuth2\Server($storage);

// Add the "Password / User Credentials" grant type
$server->addGrantType(new OAuth2\GrantType\UserCredentials($storage));

因此,这里我想使用到我自己的用户表,而不是默认的
oauth\u users
表。因为密码是咸的,我也需要进行不同的密码检查。我使用的是BShaffer OAuth2库:

有了这个库,编写自定义代码就很容易了,因此您不必触及这个库的核心。 对于此问题,您必须创建一个实现的自定义存储类。这里有两种方法需要您自己实现

public function checkUserCredentials()

public function getUserDetails()
在这里,您可以实现检查用户详细信息和获取用户详细信息的逻辑。 在此之后,您需要将此存储添加到oAuth服务器,如下所示:

$server = new OAuth2\Server($storage);
$userStorage = new YourCustomUserStorage();
$server->addStorage($userStorage, 'user_credentials');
$server->addGrantType(new OAuth2\GrantType\UserCredentials($userStorage));
您还需要将此存储传递给要添加到服务器的任何授予类型,在您的情况下,它如下所示:

$server = new OAuth2\Server($storage);
$userStorage = new YourCustomUserStorage();
$server->addStorage($userStorage, 'user_credentials');
$server->addGrantType(new OAuth2\GrantType\UserCredentials($userStorage));

嗨,我也有同样的问题你有答案吗?