Skip to content

Conversation

@samsin33
Copy link
Contributor

@samsin33 samsin33 commented Sep 10, 2025

On generating personal access token createToken() throws error which is
"Personal access client not found for '$provider' user provider. Please create one."

It occurs due to confidential() in Client model returns false as the secret attribute is hidden, but getAttributes() does the job.

Note: I tested passport along with mongodb package.

confidential() always returns false as the secret attribute is hidden.
@taylorotwell taylorotwell merged commit b52c089 into laravel:13.x Sep 10, 2025
10 checks passed
@hafezdivandari
Copy link
Contributor

This has been merged, but I see no relation between your issue (the thrown excpetion) and the changes on this PR.

It occurs due to confidential() in Client model returns false as the secret attribute is hidden.

This statement is not true?

We have passing tests for issuing PATs here: https://github.com/laravel/passport/blob/13.x/tests/Feature/PersonalAccessGrantTest.php

@samsin33
Copy link
Contributor Author

samsin33 commented Sep 10, 2025

@hafezdivandari My issue got fixed when I override the confidential() method in my custom Client model, hence the PR. May be the issue only occurs with mongo db.
Before override:

before

After override:

after

@hafezdivandari
Copy link
Contributor

I'm trying to find the source of the issue here, it may be MongoDB bug with accessing hidden attributes, or you have other overriden methods/customized client model that is causing this issue. For example I see personal_access attribute in your client which seems wierd.

@samsin33
Copy link
Contributor Author

samsin33 commented Sep 10, 2025

I overridden only confidendial() and nothing else, rest the model was compatible with mongodb as mentioned in the documentation here - https://www.mongodb.com/docs/drivers/php/laravel-mongodb/current/user-authentication/#std-label-laravel-user-auth-passport.

Once I run this artisan command - php artisan passport:client --personal
the below record is created.
image

The personal_access_client attribute is automatically added.

You can ignore the "personal_access" attribute that I added manually for testing purpose.

@samsin33
Copy link
Contributor Author

This issue only occurs with mongodb may be because of the casts, accessors and mutators, which may be not in sync with the mongodb base model. MySQL is working fine.

@Torquin
Copy link

Torquin commented Nov 5, 2025

Would this not be the same needed for the validateClient function in src/Bridge/ClientRepository as it uses :

$this->hasher->check($clientSecret, $record->secret)

But as hidden in mongodb model, $record->secret is empty. I tried this with mongodb and always get invalid client, so i extended the ClientRepository like this :

return $record && ! empty($clientSecret) && $this->hasher->check($clientSecret, $record->getAttributes()['secret']);

And it works fine now ! Sorry this might not be the correct place to post this, but it seems to be the same problem.

Thanks

@hafezdivandari
Copy link
Contributor

@samsin33 @Torquin I’d suggest reporting this issue on the laravel-mongodb package instead.

cc @GromNaN could you please weigh in? It seems that hidden attributes on an Eloquent model are not accessible when using MongoDB.

@GromNaN
Copy link

GromNaN commented Nov 5, 2025

I'm tracking this issue for investigation: PHPORM-415

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants