mezzio-authentication-oauth2
mezzio-authentication-oauth2 copied to clipboard
Wrong column types for user_id and client_id
I used the script at /data/oauth2.sql to create the database model. Here I find the following table definition:
CREATE TABLE `oauth_access_tokens` (
...
`user_id` int(10) DEFAULT NULL,
`client_id` int(10) NOT NULL,
...
);
The column types are therefore integers, which also makes sense if you want to refer to the IDs of the tables oauth_clients and oauth_users.
But then the following array is assembled in Mezzio\Authentication\OAuth2\Repository\Pdo\AccessTokenRepository:
$params = [
':id' => $accessTokenEntity->getIdentifier(),
':user_id' => $accessTokenEntity->getUserIdentifier(),
':client_id' => $accessTokenEntity->getClient()->getIdentifier(),
':scopes' => $this->scopesToString($accessTokenEntity->getScopes()),
':revoked' => 0,
':expires_at' => date(
'Y-m-d H:i:s',
$accessTokenEntity->getExpiryDateTime()->getTimestamp()
),
];
And here user_id and client_id are returned as a string, which is why the database INSERT subsequently fails and the UniqueTokenIdentifierConstraintViolationException is thrown.
I have got the same issue. like @kschroeer
Incorrect integer value: 'user_test' for column mezzio_db_local.oauth_access_tokens.user_id at row 1
my $params:
Array
(
[:id] => 5537fa43d5e5ca969f77eab2ab594cd0cbafd24460e61cc46149c559c36295da26c0c51a068e43d6
[:user_id] => user_test
[:client_id] => client_test
[:scopes] => test
[:revoked] => 0
[:expires_at] => 2020-08-12 09:38:46
)
how to modify UserRepository/ClientRepository? or we have to change integer type in DB table to varchar?
POST /oauth2/token HTTP/1.1
Host: mezzio:8080
Content-Type: application/x-www-form-urlencoded
grant_type=password&client_id=client_test&client_secret=test&scope=test&username=user_test&password=test
I decided to change the type of the field to varchar, but I believe it is not the best solution. In my opinion the ideal is that the customer's auto incremental ID should be saved, but I believe that the problem is not in the class wich @kschroeer mentioned, but in:
Mezzio\Authentication\OAuth2\Repository\Pdo\ClientRepository
This is the class that generates the client entity, therefore it is the one that populates the client's identifier for Mezzio\Authentication\OAuth2\Repository\Pdo\AccessTokenRepository.
This only forwards the received identifier to the entity instead of searching for the ID in the table:
/**
* {@inheritDoc}
*/
public function getClientEntity($clientIdentifier) : ?ClientEntityInterface
{
$clientData = $this->getClientData($clientIdentifier);
if (empty($clientData)) {
return null;
}
return new ClientEntity(
$clientIdentifier,
$clientData['name'] ?? '',
$clientData['redirect'] ?? '',
(bool) ($clientData['is_confidential'] ?? null)
);
}
Now I'm running out of time, but I'll try to take a look at this in the next few days, in case nobody solves it before ... heheeh
Same issue in V2.1.0 Still don't know if the user_id should be the id field in user table, or the username.
UserRepository create the user with the username as Identifier
return new UserEntity($username);
I have got the same issue when send user info to TokenEndpointHandler for request token, ( grant_type = password)
reterun this error:
{
“error”: “access_token_duplicate”,
“error_description”: “Could not create unique access token identifier”,
“message”: “Could not create unique access token identifier”
}
and, i found this error from here:
./vendor/mezzio/mezzio-authentication-oauth2/src/Repository/Pdo/AccessTokenRepository.php
Method persistNewAccessToken() sets values to table oauth_access_tokens, fields user_id and client_id set values as strings, but columns type is integer
I have the same issue. Is there any fix for it?
Edit: Seems like the version that support PHP 7.3 still has this bug. May be it's discontinued.
Send patches, if you have a reproducible test case.
@Ocramius I will give you the steps I followed which lead to this issue with version 2.41
- Installed the mezzio skeleton app from https://docs.mezzio.dev/mezzio/ without any template renders
- Installed this package from https://docs.mezzio.dev/mezzio-authentication-oauth2/
- Followed the instructions from https://docs.mezzio.dev/mezzio-authentication-oauth2/v1/intro/ to setup
- Created mysql db structure using the two scripts provided in https://docs.mezzio.dev/mezzio-authentication-oauth2/v1/intro/#oauth2-database
- Tried to authenticate using the test credentials created above with "password" grant type.
I managed to face issues with both user_id and client_id field. The db is created with integer fields but the library tries to insert string values (username and client name) to those fields. I hope this helps. Am I using wrong scripts to create the db?
I can confirm this. When the parameters below are set in persistNewAccessToken() from class Mezzio\Authentication\OAuth2\Repository\Pdo\AccessTokenRepository, both variables will be strings, but the table 'oauth_access_tokens' is expecting integers.
':user_id' => $accessTokenEntity->getUserIdentifier(),
':client_id' => $accessTokenEntity->getClient()->getIdentifier(),

At the risk of sounding like a broken record again: send patches with automated tests, please.