thephpleague / oauth2-server

A spec compliant, secure by default PHP OAuth 2.0 Server
https://oauth2.thephpleague.com
MIT License
6.49k stars 1.12k forks source link

Always validate client #1420

Open hafezdivandari opened 5 days ago

hafezdivandari commented 5 days ago

This PR can be considered as a security enhancement and does 2 changes:

  1. Always validate client:
    • The auth code grant - Unlike all other grants - calls AbstractGrant::validateClient() only if the client is confidential, this causes issue when the client is not confidential but we want to check if the client handles the requested grant type or not. The ClientRepository::validateClient() implementation can easily check if the client is confidential itself before verifying the client secret as we already do on Laravel Passport. This PR makes the server always call AbstractGrant::validateClient().
    • The auth code grant and client credential grants unnecessarily call AbstractGrant::getClientEntityOrFail() twice instead of just using the AbstractGrant::validateClient() return value, this PR fixes that.
  2. Pass grant type to ClientRepositoryInterface::getClientEntity():
    • Currently there is no way to check if the client handles the grant type before proceeding the request, e.g. We don't want to make auth code on "auth code grant" or make device code on "device code auth" grant or response with the access token on "implicit token" grant if the specified client doesn't handle the grant type. This PR makes this possible to avoid handling the requested grant type if the specified client doesn't supports that.