jeremy379 / laravel-openid-connect

Implement OpenID Connect inside Laravel
MIT License
25 stars 11 forks source link

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

Closed alecpl closed 1 month ago

alecpl commented 1 month ago

As mentioned in https://github.com/laravel/passport/pull/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 commented 1 month ago

Seems legit, thanks.

alecpl commented 1 month ago

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.