From 324da27ea9a7c441c2d75c50fe4082b3ddc565a4 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Mon, 4 Aug 2014 15:26:56 +0100 Subject: [PATCH] Added verify credentials callback --- examples/relational/other_grants.php | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/examples/relational/other_grants.php b/examples/relational/other_grants.php index 2951c720..495af38b 100644 --- a/examples/relational/other_grants.php +++ b/examples/relational/other_grants.php @@ -27,16 +27,21 @@ $server->setAuthCodeStorage(new Storage\AuthCodeStorage); $clientCredentials = new \League\OAuth2\Server\Grant\ClientCredentialsGrant(); $server->addGrantType($clientCredentials); + $passwordGrant = new \League\OAuth2\Server\Grant\PasswordGrant(); +$passwordGrant->setVerifyCredentialsCallback(function ($username, $password) { + $result = (new Model\Users())->get($username); + if (count($result) !== 1) { + return false; + } + + if (password_verify($password, $result[0]['password'])) { + return $username; + } + + return false; +}); $server->addGrantType($passwordGrant); -$refrehTokenGrant = new \League\OAuth2\Server\Grant\RefreshTokenGrant(); -$server->addGrantType($refrehTokenGrant); -$clientCredentials = new \League\OAuth2\Server\Grant\ClientCredentialsGrant(); -$server->addGrantType($clientCredentials); -$passwordGrant = new \League\OAuth2\Server\Grant\PasswordGrant(); -$server->addGrantType($passwordGrant); -$refrehTokenGrant = new \League\OAuth2\Server\Grant\RefreshTokenGrant(); -$server->addGrantType($refrehTokenGrant); // $refrehTokenGrant = new \League\OAuth2\Server\Grant\RefreshTokenGrant(); // $server->addGrantType($refrehTokenGrant);