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

WebToken support integration #1041

Merged
merged 1 commit into from
Dec 1, 2023
Merged

Conversation

Spomky
Copy link
Contributor

@Spomky Spomky commented Jun 26, 2022

This PR aims to integrate Web-Token for issuing and verifying access tokens.
The two processes are separated so that it is possible to issue a token on one server and verify them on another.

The configuration looks like as follow

lexik_jwt_authentication:
    encoder:
        service: lexik_jwt_authentication.encoder.web_token #New encoder
    access_token_issuance:
        enabled: true
        signature: # Access tokens are always signed
            algorithm: 'HS256' # Signature/MAC algorithm.
            key: '%env(LEXIK_SIGNATURE_KEY)%' # Signature/MAC key (private or shared key, JWK format)
        encryption: # Access token may be encrypted
            enabled: true
            key_encryption_algorithm: 'A256GCMKW' # Key Encryption Algorithm.
            content_encryption_algorithm: 'A256GCM' # Content Encryption Algorithm.
            key: '%env(LEXIK_ENCRYPTION_KEY)%' # Encryption key (public or shared key, JWK format)
    access_token_verification:
        enabled: true
        signature: # Received Access tokens shall always be signed
            allowed_algorithms: ['HS256', 'RS256'] # List of allowed signature/MAC algorithms
            keyset: '%env(LEXIK_ALLOWED_SIGNATURE_KEYSET)%' # Signature verification keys (public or shared keys, JWKSet format)
        encryption:
            enabled: true: # Received Access tokens may be encrypted
            allowed_key_encryption_algorithms: ['A256GCMKW', 'ECDH-ES+A128KW'] # List of allowed key encryption algorithms
            allowed_content_encryption_algorithms: ['A256GCM', 'A128CBC-HS256'] # List of allowed content encryption algorithms
            keyset: '%env(LEXIK_ALLOWED_ENCRYPTION_KEYSET)%' # Decryption keys (private or shared keys, JWKSet format)

Note
To work with this feature, the application shall install the associated bundle and the algorithms to be used:

composer require web-token/jwt-bundle
composer require web-token/jwt-checker

composer require web-token/jwt-signature-algorithm-hmac
composer require web-token/jwt-encryption-algorithm-aesgcm
composer require web-token/jwt-encryption-algorithm-aesgcmkw

Complete lists of supported algorithms:

Warning
This feature is NOT compatible with the cookie split feature!

  • Documentation
  • JWT Builder
    • Signature alg+key
    • Encryption algs+key
    • Additional claims and header
    • Allow additional claims and header to be disable (removed as too risky)
    • Allow custom JWE header
  • JWT Loader
    • Decryption algs+keyset
    • Verification algs+keyset
    • JWS claims and header checkers
    • JWE header checkers
    • Allow non-encrypted tokens even if encryption support is enable
  • Commands
    • Configuration migration + Key conversion
    • Encryption Support Helper
    • Keyset Rotation Helper (will be part of another PR)
  • Tests
    • Success
      • Token issuance
      • Token verification
    • Failure
      • Not encrypted
      • Cannot be decrypted
        • Unsupported key encryption algorithm
        • Unsupported content encryption algorithm
        • Missing decryption key
      • Bad content
      • Bad signature
      • Unsupported signature algorithm
      • Missing verification key
      • Time sensitive (expired, not yet...)
      • Mandatory claims are missing

@Spomky Spomky marked this pull request as draft June 26, 2022 19:57
@Spomky Spomky marked this pull request as ready for review June 26, 2022 21:30
@Spomky
Copy link
Contributor Author

Spomky commented Jun 30, 2022

Hi @chalasr and all,

It looks good to me. Can you please take time to review this PR and let me know if you see issues, feature or anything that should be addressed here.

Many thanks,
Regards.

@chalasr
Copy link
Collaborator

chalasr commented Jul 5, 2022

Thanks for the amazing work @Spomky. Review on its way :)

Copy link
Collaborator

@chalasr chalasr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First round of comments and questions :)

Tests/Functional/Command/MigrateConfigCommandTest.php Outdated Show resolved Hide resolved
Services/WebToken/AccessTokenLoader.php Outdated Show resolved Hide resolved
Services/WebToken/AccessTokenLoader.php Outdated Show resolved Hide resolved
Services/WebToken/AccessTokenLoader.php Outdated Show resolved Hide resolved
Resources/doc/index.rst Outdated Show resolved Hide resolved
Command/MigrateConfigCommand.php Outdated Show resolved Hide resolved
Command/MigrateConfigCommand.php Outdated Show resolved Hide resolved
Events.php Show resolved Hide resolved
DependencyInjection/LexikJWTAuthenticationExtension.php Outdated Show resolved Hide resolved
Services/WebToken/AccessTokenLoader.php Show resolved Hide resolved
Copy link
Collaborator

@chalasr chalasr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more comments :) I'm really looking forward to merge this.
Also FYI version the 3.x branch of this bundle is going to require PHP 8.1 minimum, so we will be able to remove the specificities there.

DependencyInjection/Configuration.php Outdated Show resolved Hide resolved
Encoder/WebTokenEncoder.php Outdated Show resolved Hide resolved
Encoder/WebTokenEncoder.php Outdated Show resolved Hide resolved
Encoder/WebTokenEncoder.php Outdated Show resolved Hide resolved
Encoder/WebTokenEncoder.php Outdated Show resolved Hide resolved
Encoder/WebTokenEncoder.php Outdated Show resolved Hide resolved
DependencyInjection/LexikJWTAuthenticationExtension.php Outdated Show resolved Hide resolved
@Spomky Spomky force-pushed the features/new-config branch 2 times, most recently from c36ec94 to 1d0b7ca Compare April 2, 2023 16:20
@Spomky
Copy link
Contributor Author

Spomky commented Apr 2, 2023

Hi,

I rebased the and finished the last things including the documentation.
If anyone passing here can test it, I'll be happy to receive comments and feedback on it.

Many thanks.

@chalasr
Copy link
Collaborator

chalasr commented Dec 1, 2023

It took time, but here we go, this is in now. Thank you very much @Spomky.

@chalasr chalasr merged commit 63a9811 into lexik:2.x Dec 1, 2023
10 checks passed
chalasr added a commit that referenced this pull request Dec 1, 2023
… with PHP 7.x (webhdx)

This PR was merged into the 2.x branch.

Discussion
----------

Removed constructor property promotion to fix compatibility with PHP 7.x

Looks like #1041 introduced PHP 7.x incompatible change. The issue is constructor property promotion in `\Lexik\Bundle\JWTAuthenticationBundle\Command\EnableEncryptionConfigCommand` class.

Commits
-------

dd21e04 Removed constructor property promotion to fix compatibility with PHP 7.x
@Spomky Spomky deleted the features/new-config branch December 1, 2023 19:33
@Spomky
Copy link
Contributor Author

Spomky commented Dec 1, 2023

Excellent! TBH I missed this PR and forget to have it in line with the branch.
Let me know if there is any trouble with this feature and I will take care of it.

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