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

Make possible to use encryption key object for better performance #21

Merged
merged 1 commit into from
Aug 1, 2024

Conversation

alecpl
Copy link
Contributor

@alecpl alecpl commented Aug 1, 2024

As mentioned in laravel/passport#820 it gives better performance.

Implementations can override the internal method to return an object without a need to override the whole makeAuthorizationServer() method.

@jeremy379
Copy link
Owner

Seems legit, thanks.

@jeremy379 jeremy379 merged commit 01e9b1e into jeremy379:main Aug 1, 2024
2 checks passed
@alecpl
Copy link
Contributor Author

alecpl commented Aug 1, 2024

FYI, this is what I'm using in my provider.

   /**
     * Create a Key instance for encrypting the refresh token
     *
     * Based on https://github.com/laravel/passport/pull/820
     *
     * @param string $keyBytes
     * @return \Defuse\Crypto\Key|string
     */
    protected function getEncryptionKey($keyBytes)
    {
        // First, we will encode Laravel's encryption key into a format that the Defuse\Crypto\Key class can use,
        // so we can instantiate a new Key object. We need to do this as the Key class has a private constructor method
        // which means we cannot directly instantiate the class based on our Laravel encryption key.
        $encryptionKeyAscii = EncryptionEncoding::saveBytesToChecksummedAsciiSafeString(
            EncryptionKey::KEY_CURRENT_VERSION,
            $keyBytes
        );

        // Instantiate a Key object so we can take advantage of significantly faster encryption/decryption
        // from https://github.com/thephpleague/oauth2-server/pull/814. The improvement is 200x-300x faster.
        return EncryptionKey::loadFromAsciiSafeString($encryptionKeyAscii);
    }

If you'd be interested we could include that in your package, but make it optional. This way there would be less code needed on the application side.

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