bshaffer / oauth2-server-php

A library for implementing an OAuth2 Server in php
http://bshaffer.github.io/oauth2-server-php-docs
MIT License
3.26k stars 950 forks source link

Using UserCredentials grant type not working with Pdo storage object #977

Closed jkingstonc closed 4 years ago

jkingstonc commented 4 years ago

Hi, I have created a Pdo storage object, a server and a UserCredentials grant type. I have also inserted an entry into the db in the oauth_users schema. However, the server doesn't seem to be able to recognize the user credentials? I can use other grant types but UserCredentials doesn't seem to work?

$storage = new OAuth2\Storage\Pdo(array('dsn' => $database, 'username' => $username, 'password' => $password)); $server = new OAuth2\Server($storage); $server->addGrantType(new OAuth2\GrantType\UserCredentials($storage));

This is my oauth_users table: https://imgur.com/xqZpKD3

bshaffer commented 4 years ago

Your password should not be stored in plaintext, and this library does not recognize passwords stored this way. By default the library uses sha1 to store a password, e.g. from your command line:

$ php -r 'echo sha1("somepassword") . "\n";'

This will output f8377c90fcfd699f0ddbdcb30c2c9183d2d933ea, which if stored in the password column of your database, will work as you expect.