Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[13.x] Improve performance, fix minor bugs, and add tests #1783

Merged
merged 16 commits into from
Sep 19, 2024

Conversation

hafezdivandari
Copy link
Contributor

@hafezdivandari hafezdivandari commented Aug 26, 2024

This PR does:

  • Implement the Arrayable, Jsonable, and JsonSerializable interfaces on the AccessToken class and fix some minor issues.
  • Move repeated logic for determining scope existence to the ResolvesInheritedScopes trait by introducing a new scopeExists method, used in both the AccessToken and Client classes.
  • Fix a bug when empty scopes was causing authorization to skip and add tests for this.
  • Drop support for Laravel 10 and PHP 8.1.
  • Make the ClientRepository class a singleton and leverages the new Laravel 11 once function, avoids duplicate queries to retrieve the same client. For example, when issuing a token using the auth code grant, this change reduces the number of queries executed by three:
Before After
  1. select * from "oauth_clients" where "id" = '9cda...' limit 1
  2. select * from "oauth_clients" where "id" = '9cda...' limit 1
  3. select * from "oauth_clients" where "id" = '9cda...' limit 1
  4. select exists(select * from "oauth_auth_codes" where "id" = '0ab0...' and "revoked" = 0) as "exists"
  5. select * from "oauth_clients" where "id" = '9cda...' limit 1
  6. insert into "oauth_access_tokens" ("id", "user_id", "client_id", "scopes", "revoked", "created_at", "updated_at", "expires_at") values ('36ef...', '1', '9cda...', '["create","read"]', 0, '2024-08-26 02:03:54', '2024-08-26 02:03:54', '2025-08-26 02:03:54')
  7. insert into "oauth_refresh_tokens" ("id", "access_token_id", "revoked", "expires_at") values ('0ed5...', 0, '2025-08-26 02:03:54')
  8. update "oauth_auth_codes" set "revoked" = 1 where "id" = '0ab0...'
  1. select * from "oauth_clients" where "id" = '9cda...' limit 1
  2. select exists(select * from "oauth_auth_codes" where "id" = '0ab0...' and "revoked" = 0) as "exists"
  3. insert into "oauth_access_tokens" ("id", "user_id", "client_id", "scopes", "revoked", "created_at", "updated_at", "expires_at") values ('36ef...', '1', '9cda...', '["create","read"]', 0, '2024-08-26 02:03:54', '2024-08-26 02:03:54', '2025-08-26 02:03:54')
  4. insert into "oauth_refresh_tokens" ("id", "access_token_id", "revoked", "expires_at") values ('0ed5...', 0, '2025-08-26 02:03:54')
  5. update "oauth_auth_codes" set "revoked" = 1 where "id" = '0ab0...'

Copy link

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@hafezdivandari hafezdivandari marked this pull request as ready for review September 18, 2024 20:53
@taylorotwell taylorotwell merged commit d16746c into laravel:13.x Sep 19, 2024
4 checks passed
@hafezdivandari hafezdivandari deleted the 13.x-finalize-scopes branch September 19, 2024 11:52
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.

2 participants