oauth2-server icon indicating copy to clipboard operation
oauth2-server copied to clipboard

Testing v9-rc1 on Laravel Passport

Open hafezdivandari opened this issue 1 year ago • 13 comments

Trying to add support and test v9-rc1 before stable release on Laravel Passport, PR laravel/passport#1734, there are 2 issues:

  1. User ID doesn't accept integer
  2. Client ID doesn't accept integer

You may check the failed tests here: https://github.com/laravel/passport/actions/runs/8482967241/job/23243211337?pr=1734

Both User and Client classes of Laravel Passport are using League\OAuth2\Server\Entities\Traits\EntityTrait.

  • [x] This trait accepts mixed id on set but return string on get:

    https://github.com/thephpleague/oauth2-server/blob/ca511c14fca93ffc0f518370492c2476e7b0e4f7/src/Entities/Traits/EntityTrait.php#L22-L33

  • [x] Also on the TokenInterface class, $userIdentifier type doesn't match on set / get :

    https://github.com/thephpleague/oauth2-server/blob/ca511c14fca93ffc0f518370492c2476e7b0e4f7/src/Entities/TokenInterface.php#L39-L49

  • [x] On AccessTokenRepositoryInterface the $userIdentifier property accepts mixed:

    https://github.com/thephpleague/oauth2-server/blob/ca511c14fca93ffc0f518370492c2476e7b0e4f7/src/Repositories/AccessTokenRepositoryInterface.php#L33

  • [x] On AbstractGrant class, getClientEntityOrFail method accepts only string $clientId and not int:

    https://github.com/thephpleague/oauth2-server/blob/ca511c14fca93ffc0f518370492c2476e7b0e4f7/src/Grant/AbstractGrant.php#L187

  • [x] On ClientRepositoryInterface class, getClientEntity and validateClient methods, $clientIdentifier argument doesn't accept int:

    https://github.com/thephpleague/oauth2-server/blob/ca511c14fca93ffc0f518370492c2476e7b0e4f7/src/Repositories/ClientRepositoryInterface.php#L25-L30

hafezdivandari avatar Mar 29 '24 16:03 hafezdivandari

Thanks so much for this @hafezdivandari. This is super useful. I suspected the change of IDs might cause issues downstream so great to have something concrete to work with. Really appreciate you doing this

Sephster avatar Mar 29 '24 21:03 Sephster

Thank you @Sephster for your hard work in maintaining this package and the new major release. I'll keep an eye on this issue until it is resolved. Please let me know when we are able to move the PR forward. Thanks.

hafezdivandari avatar Mar 30 '24 12:03 hafezdivandari

I think I've fixed all the issues raised here now @hafezdivandari - thanks again for creating the PR for Passport. Would you be able to check if this has resolved all issues now? Once we have a working, v9 compatible version of Passport, I will look to tag v9 proper. Thanks again for progressing this. Much appreciated.

Sephster avatar Apr 14 '24 21:04 Sephster

@Sephster I applied the latest changes. I'm checking failed test...

hafezdivandari avatar Apr 14 '24 22:04 hafezdivandari

@Sephster all tests are passing. We may close this issue as completed now, Thank you.

hafezdivandari avatar Apr 14 '24 22:04 hafezdivandari

Hi, @Sephster This library should treat any identifiers as strings. This will avoid constant conversions to a string when composing a response. The only thing that needs to be provided is the conversion of identifiers from a query to a string in order to avoid type mismatch errors. Knowing the true data type of the identifier is the task of the application that uses this library.

The introduction of an integer identifier is a step back in the implementation of typing.

eugene-borovov avatar Apr 15 '24 03:04 eugene-borovov

I can see the case for this argument. Part of the reason I originally had the identifiers as strings initially was to avoid casting when things come in from http requests.

@hafezdivandari what are your thoughts on this? Would a simple case of casting fix most compatibility issues with Passport?

You still raised some excellent points so I won't revert all changes but I'm leaning towards treating identifiers as strings only as @eugene-borovov suggests

Sephster avatar Apr 15 '24 07:04 Sephster

@Sephster I`d like to remind about this issue. This change help to cast all request parameters to string.

eugene-borovov avatar Apr 15 '24 10:04 eugene-borovov

No problem @Sephster, let's make the types more strict and see what happens on Laravel Passport tests. I'll try to cast the arguments.

hafezdivandari avatar Apr 15 '24 10:04 hafezdivandari

Changes made now @hafezdivandari - if you can see how you get on with the PR, I can merge this into main assuming all is ok. Apologies for the delay with this as well, I was travelling with my family.

Sephster avatar Apr 22 '24 21:04 Sephster

Thank you @Sephster, have a nice trip. Just commented a little issue on the PR: https://github.com/thephpleague/oauth2-server/pull/1402#issuecomment-2071005717

hafezdivandari avatar Apr 22 '24 21:04 hafezdivandari

It was great thank you. Thanks for spotting that. I've fixed the issue reported now.

Sephster avatar Apr 22 '24 21:04 Sephster

@Sephster 6 tests are failing on Laravel Passport rn, I added a comment on the PR: https://github.com/thephpleague/oauth2-server/pull/1402#issuecomment-2071030766 I hope this is the last one.

hafezdivandari avatar Apr 22 '24 22:04 hafezdivandari