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

Use a Key object when instantiating AuthorizationServer for 200x-300x faster encryption of refresh token #820

Closed
wants to merge 2 commits into from

Conversation

EricTendian
Copy link

Right now, it can be quite slow to generate a new access and refresh token due to having to use the PBKFD2 hash function, which can account for over 50% of time spent generating an access token in most cases. I found an issue on the oauth2-server package which describes this issue in more detail: thephpleague/oauth2-server#812

Since the encryption key Laravel uses already comes from the random_bytes function, it is secure enough to use as-is. We are also storing the key server-side, so there isn't a big need to use a password hashing key generation function when trying to encrypt the refresh token.

The PR thephpleague/oauth2-server#814 implements a fix (released on version 7.x of the library), by allowing the authorization server to be instantiated with a Key object instead of a string. By taking advantage of this and passing in an instantiated key, I was able to get a 290x speed improvement over 1000 iterations of encrypting a refresh token (2+ mins to 0.5s). Other machines may have similar performance gains.

I have verified that Passport continues to work as normal with this change. This change can be backported to Passport 6.0 as that version also has version 7.x of the OAuth2 library. (I can make a separate PR for the backport once this one is approved)

@taylorotwell
Copy link
Member

Is this a breaking change for tokens that have already been issued?

@EricTendian
Copy link
Author

@taylorotwell Good catch, in the current state of this PR it would be a breaking change. However, I have found a solution to preserve backwards-compatibility and have made a PR in the OAuth2 server repo for it: thephpleague/oauth2-server#941

As such, it might be worth waiting on that other PR to get merged in and a new version of the package to be released before this PR is merged.

@taylorotwell
Copy link
Member

OK. Feel free to re-submit this when that is resolved.

@EricTendian
Copy link
Author

@taylorotwell based on the feedback in the other PR, it doesn't seem like this will be able to be a backwards-compatible change. Do you want to reconsider this for the next major release?

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