GithubHelp home page GithubHelp logo

symfony's Introduction

auth0/symfony

Symfony SDK for Auth0 Authentication and Management APIs.

๐Ÿ“š Documentation - ๐Ÿš€ Getting Started - ๐Ÿ’ฌ Feedback

Documentation

  • Docs site โ€” explore our docs site and learn more about Auth0.

Getting Started

Requirements

  • PHP 8.1+
  • Symfony 6.4 LTS
    • Symfony 7.0 is not currently supported.

Please review our support policy to learn when language and framework versions will exit support in the future.

Installation

Add the dependency to your application with Composer:

composer require auth0/symfony

Configure Auth0

Create a Regular Web Application in the Auth0 Dashboard. Verify that the "Token Endpoint Authentication Method" is set to POST.

Next, configure the callback and logout URLs for your application under the "Application URIs" section of the "Settings" page:

  • Allowed Callback URLs: URL of your application where Auth0 will redirect to during authentication, e.g., http://localhost:8000/callback.
  • Allowed Logout URLs: URL of your application where Auth0 will redirect to after logout, e.g., http://localhost:8000/login.

Note the Domain, Client ID, and Client Secret. These values will be used later.

Configure the SDK

After installation, you should find a new file in your application, config/packages/auth0.yaml. If this file isn't present, please create it manually.

The following is an example configuration that will use environment variables to assign values. You should avoid storing sensitive credentials directly in this file, as it will often be committed to version control.

auth0:
  sdk:
    domain: "%env(trim:string:AUTH0_DOMAIN)%"
    client_id: "%env(trim:string:AUTH0_CLIENT_ID)%"
    client_secret: "%env(trim:string:AUTH0_CLIENT_SECRET)%"
    cookie_secret: "%kernel.secret%"

    # custom_domain: "%env(trim:string:AUTH0_CUSTOM_DOMAIN)%"

    # audiences:
    #  - "%env(trim:string:AUTH0_API_AUDIENCE)%"

    # token_cache: cache.auth0_token_cache
    # management_token_cache: cache.auth0_management_token_cache

    scopes:
      - openid
      - profile
      - email
      - offline_access

  authenticator:
    routes:
      callback: "%env(string:AUTH0_ROUTE_CALLBACK)%"
      success: "%env(string:AUTH0_ROUTE_SUCCESS)%"
      failure: "%env(string:AUTH0_ROUTE_FAILURE)%"
      login: "%env(string:AUTH0_ROUTE_LOGIN)%"
      logout: "%env(string:AUTH0_ROUTE_LOGOUT)%"

Configure your .env file

Create or open a .env.local file within your application directory, and add the following lines:

#
# โ†“ Refer to your Auth0 application details (https://manage.auth0.com/#/applications) for these values.
#

# Your Auth0 application domain
AUTH0_DOMAIN=...

# Your Auth0 application client ID
AUTH0_CLIENT_ID=...

# Your Auth0 application client secret
AUTH0_CLIENT_SECRET=...

# Optional. Your Auth0 custom domain, if you have one. (https://manage.auth0.com/#/custom_domains)
AUTH0_CUSTOM_DOMAIN=...

# Optional. Your Auth0 API identifier/audience, if used. (https://manage.auth0.com/#/apis)
AUTH0_API_AUDIENCE=...

#
# โ†“ These routes will be used by the SDK to direct traffic during authentication.
#

# The route that SDK will redirect to after authentication:
AUTH0_ROUTE_CALLBACK=callback

# The route that will trigger the authentication process:
AUTH0_ROUTE_LOGIN=login

# The route that the SDK will redirect to after a successful authentication:
AUTH0_ROUTE_SUCCESS=private

# The route that the SDK will redirect to after a failed authentication:
AUTH0_ROUTE_FAILURE=public

# The route that the SDK will redirect to after a successful logout:
AUTH0_ROUTE_LOGOUT=public

Please ensure this .env.local file is included in your .gitignore. It should never be committed to version control.

Configure your security.yaml file

Open your application's config/packages/security.yaml file, and update it based on the following example:

security:
  providers:
    auth0_provider:
      id: Auth0\Symfony\Security\UserProvider

  firewalls:
    auth0:
      pattern: ^/private$ # A pattern example for stateful (session-based authentication) route requests
      provider: auth0_provider
      custom_authenticators:
        - auth0.authenticator
    api:
      pattern: ^/api # A pattern example for stateless (token-based authorization) route requests
      stateless: true
      provider: auth0_provider
      custom_authenticators:
        - auth0.authorizer
    dev:
      pattern: ^/(_(profiler|wdt)|css|images|js)/
      security: false
    main:
      lazy: true

  access_control:
    - { path: ^/api$, roles: PUBLIC_ACCESS } # PUBLIC_ACCESS is a special role that allows everyone to access the path.
    - { path: ^/api/scoped$, roles: ROLE_USING_TOKEN } # The ROLE_USING_TOKEN role is added by the Auth0 SDK to any request that includes a valid access token.
    - { path: ^/api/scoped$, roles: ROLE_READ_MESSAGES } # This route will expect the given access token to have the `read:messages` scope in order to access it.

Update your config/bundle.php

The SDK bundle should be automatically detected and registered by Symfony Flex projects, but you may need to add the Auth0Bundle to your application's bundle registry. Either way, it's a good idea to register the bundle anyway, just to be safe.

<?php

return [
    /*
     * Leave any existing entries in this array as they are.
     * You should just append this line to the end:
     */

    Auth0\Symfony\Auth0Bundle::class => ['all' => true],
];

Optional: Add Authentication helper routes

The SDK includes a number of pre-built HTTP controllers that can be used to handle authentication. These controllers are not required, but can be helpful in getting started. In many cases, these may provide all the functionality you need to integrate Auth0 into your application, providing a plug-and-play solution.

To use these, open your application's config/routes.yaml file, and add the following lines:

login: # Send the user to Auth0 for authentication.
  path: /login
  controller: Auth0\Symfony\Controllers\AuthenticationController::login

callback: # This user will be returned here from Auth0 after authentication; this is a special route that completes the authentication process. After this, the user will be redirected to the route configured as `AUTH0_ROUTE_SUCCESS` in your .env file.
  path: /callback
  controller: Auth0\Symfony\Controllers\AuthenticationController::callback

logout: # This route will clear the user's session and return them to the route configured as `AUTH0_ROUTE_LOGOUT` in your .env file.
  path: /logout
  controller: Auth0\Symfony\Controllers\AuthenticationController::logout

Recommended: Configure caching

The SDK provides two caching properties in it's configuration: token_cache and management_token_cache. These are compatible with any PSR-6 cache implementation, of which Symfony offers several out of the box.

These are used to store JSON Web Key Sets (JWKS) results for validating access token signatures and generated management API tokens, respectively. We recommended configuring this feature to improve your application's performance by reducing the number of network requests the SDK needs to make. It will also greatly help in avoiding hitting rate-limiting conditions, if you're making frequent Management API requests.

The following is an example config/packages/cache.yaml file that would configure the SDK to use a Redis backend for caching:

framework:
  cache:
    prefix_seed: auth0_symfony_sample

    app: cache.adapter.redis
    default_redis_provider: redis://localhost

    pools:
      auth0_token_cache: { adapter: cache.adapter.redis }
      auth0_management_token_cache: { adapter: cache.adapter.redis }

Please review the Symfony cache documentation for adapter-specific configuration options. Please note that the SDK does not currently support Symfony's "Cache Contract" adapter type.

Example: Retrieving the User

The following example shows how to retrieve the authenticated user within a controller. For this example, we'll create a mock ExampleController class that is accessible from a route at /private.

Add a route to your application's config/routes.yaml file:

private:
  path: /private
  controller: App\Controller\ExampleController::private

Now update or create a src/Controller/ExampleController.php class to include the following code:

<?php

namespace App\Controller;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

class ExampleController extends AbstractController
{
    public function private(): Response
    {
        return new Response(
            '<html><body><pre>' . print_r($this->getUser(), true) . '</pre> <a href="/logout">Logout</a></body></html>'
        );
    }
}

If you visit the /private route in your browser, you should see the authenticated user's details. If you are not already authenticated, you will be redirected to the /login route to login, and then back to /private afterward.

Support Policy

Our support windows are determined by the Symfony release support and PHP release support schedules, and support ends when either the Symfony framework or PHP runtime outlined below stop receiving security fixes, whichever may come first.

SDK Version Symfony Version PHP Version Support Ends
5 6.2 8.2 Jul 31 2023
8.1 Jul 31 2023
6.1 8.2 Jan 31 2023
8.1 Jan 31 2023

Deprecations of EOL'd language or framework versions are not considered a breaking change, as Composer handles these scenarios elegantly. Legacy applications will stop receiving updates from us, but will continue to function on those unsupported SDK versions.

Note: We do not currently support Symfony LTS versions, but anticipate adding support for this when Symfony's 6.x branch enters it's LTS window.

Feedback

Contributing

We appreciate feedback and contribution to this repo! Before you get started, please see the following:

Raise an issue

To provide feedback or report a bug, please raise an issue on our issue tracker.

Vulnerability Reporting

Please do not report security vulnerabilities on the public Github issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.


Auth0 Logo

Auth0 is an easy to implement, adaptable authentication and authorization platform.
To learn more checkout Why Auth0?

This project is licensed under the MIT license. See the LICENSE file for more info.

symfony's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

symfony's Issues

Optional field `secret_base64_encoded` does not work.

The optional configuration field secret_base64_encoded doesn't work when set to false.

Auth0JWT::decode will always attempt to decode the secret, even if it was never base64encoded to begin with, and verifying the signature fails.

`jwt-auth-bundle` v5 development thread

This thread is to provide updates and centralize discussion around the forthcoming 5.0 major release of jwt-auth-bundle, currently in development. As conversations had begun to splinter across a few separate issues on the subject, I thought it in our best interest to have a central place to bridge these discussions.

The 5.x-dev branch is the in-development branch representing this work. Feedback, PRs, and testing are greatly appreciated. As this branch approaches what we consider beta ready, we'll merge it into main and begin cutting pre-production releases for testing. (Until then, it should be considered experimental, unstable and has not undergone a security review yet.)

Goals for 5.0 include:
๐ŸŸข Support for the new SF 5.1+ authenticator-based security, as contributed by @mcsky
๐ŸŸข Support for SF 6, as contributed by @mkilmanas
๐Ÿšง Migration to Auth0-PHP SDK 8.0 by @evansims

Note that the new 5.x bundle release will not include support for SF versions before 5.2 or PHP versions before 7.4.

Auth0 does not currently have a timeline for a stable release on this major, but will keep you informed.

Broken link to "Symfony API Quickstart Guide" in readme

Description

In the Readme the link to your own "Symfony API Quickstart Guide is broken. Expected a link to a Symfony Quickstart Guide.

Reproduction

In the resources section of the readme click the link to "Symfony API Quickstart Guides" which links here

Environment

Please provide the following:

  • Version of this library used: 3.3.1

"Undefined index: environment" on composer install

Hi!

Im getting

In InformationHeaders.php line 128:
                                        
  Notice: Undefined index: environment

when i run composer require auth0/jwt-auth-bundle:"^3.0" on a SF4 application. Using PHP 7.2-10. I can bypass that by disabling notices, but i guess we should check if the field exists before accessing it. Or should it be env instead of environment?

image

Using jwt-auth-bundle with symfony 6

Hello there,
I've been creating recently a new symfony app and planned to use auth0 as my authentification system.
I encountered an error while running

composer require auth0/jwt-auth-bundle

which lead to latest stable version 4.0.0.

After some research i found that there was an issue with the new authenticator systems embedded with symfony 6 and found this PR which has been merged and released with version 4.0.0 : #121

But it seems that the required level of symfony in the composer.json still does not allow symfony 6.

"symfony/framework-bundle": "^4.4 || ~5.1",

I don't know yet if it's a mistake or intended for any non related reasons :O

Symfony 3.0 Upgrade

Yesterday I raised a PR #22, but in using the bundle in Symfony 3 I had to make a few more changes. These changes won't work in the Symfony 2.x branches. This is because of the location of SimplePreAuthenticatorInterface in the files directory.

What is the process of requesting a merge in this instance? I was going to create a new PR, but that would break the 1.2 branch from working with Symfony 2.x.

Allow multiple audiences in config

I have two clients in auth0 one for a PWA and one for a native apps. Both should communicate with a Symfony API where I use this bundle.

As I see, the JWTVerifier is capable to validate token for mutliple audience but the auth0Service use only one audience.

PHP 8 support

Hello,

The 8th version of PHP was released last month. It could be great to support it.

I don't know if you guys have any plan to support it or if you rely on the community to do so.
I didn't take time (yet) to investigate what change should be made to ensure the PHP 8 compatibility

Looks like your recipe isn't working. As a result the bundles file isn't being updated.

Describe the problem

Looks like your recipe isn't working. As a result the bundles file isn't being updated.

What was the expected behavior?

At a minimum, the configuration noted on here should be done automatically via recipes.
I managed to get around it by following your instructions, however, the one key piece that was missing was the addition of the bundle file to the bundles.php in symfony.

As a workaround, if users are seeing messages like: There is no extension able to load the configuration for "auth0" [...]
It's just adding the following line to your bundles.php

Auth0\Symfony\Auth0Bundle::class => ['all' => true]

Here's a full example of what the bundles.php should look like:


<?php

return [
    Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
    Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
    Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
    Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true],
    Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
    Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
    Twig\Extra\TwigExtraBundle\TwigExtraBundle::class => ['all' => true],
    Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
    Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
    Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
    Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true],
    Auth0\Symfony\Auth0Bundle::class => ['all' => true],
];

Reproduction

  • create a fresh symfony project.
  • issue a composer require auth0/symfony
  • recipe should run which does all the configuration.

Environment

  • PHP 8.2
  • Symfony 6.2.4

Allow to change the url jwks.json.

I use your bundle against our own JWT provider.

In the bundle, the url for retrieving the jwks is hard coded with the value .well-known/jwks.json
But the url for retrieving jwks on our provider is /.well-known/openid-configuration/jwks.

How can I configure this value with what I need?

Remove SimplePreAuthenticatorInterface?

Thanks for merging #75!

Looking at the logs, I still get the following deprecation message:

The "Auth0\JWTAuthBundle\Security\JWTAuthenticator" class implements "Symfony\Component\Security\Http\Authentication\SimplePreAuthenticatorInterface" that is deprecated since Symfony 4.2, use Guard instead.

Since Guard is supported since SF 2.8, and the current latest supported release is 3.4.31, is it possible to remove the SimplePreAuth implementation alltogether?

Argument must implement interface 'JWTUserProviderInterface' though it's been implemented

After Setting JwtAuthBundle through Documentation, I'm getting Argument must implement interface Auth0\JWTAuthBundle\Security\Core\JWTUserProviderInterface.

Checked my code and its ok, thought it might be a bud or something..., here is the trace:

Doctrine\Common\Proxy\Exception\InvalidArgumentException: Argument must implement interface Auth0\JWTAuthBundle\Security\Core\JWTUserProviderInterface
    at n/a
        in /home/aien/Web/MrAlef/MRA/vendor/auth0/jwt-auth-bundle/src/Security/JWTAuthenticator.php line 73

    at Auth0\JWTAuthBundle\Security\JWTAuthenticator->authenticateToken(object(PreAuthenticatedToken), object(EmailUserProvider), 'secured_area')
        in /home/aien/Web/MrAlef/MRA/vendor/symfony/symfony/src/Symfony/Component/Security/Core/Authentication/Provider/SimpleAuthenticationProvider.php line 37

    at Symfony\Component\Security\Core\Authentication\Provider\SimpleAuthenticationProvider->authenticate(object(PreAuthenticatedToken))
        in /home/aien/Web/MrAlef/MRA/vendor/symfony/symfony/src/Symfony/Component/Security/Core/Authentication/AuthenticationProviderManager.php line 80

    at Symfony\Component\Security\Core\Authentication\AuthenticationProviderManager->authenticate(object(PreAuthenticatedToken))
        in /home/aien/Web/MrAlef/MRA/vendor/symfony/symfony/src/Symfony/Component/Security/Http/Firewall/SimplePreAuthenticationListener.php line 91

    at Symfony\Component\Security\Http\Firewall\SimplePreAuthenticationListener->handle(object(GetResponseEvent))
        in /home/aien/Web/MrAlef/MRA/vendor/symfony/symfony/src/Symfony/Component/Security/Http/Firewall.php line 69

    at Symfony\Component\Security\Http\Firewall->onKernelRequest(object(GetResponseEvent), 'kernel.request', object(TraceableEventDispatcher))
        in  line 

    at call_user_func(array(object(Firewall), 'onKernelRequest'), object(GetResponseEvent), 'kernel.request', object(TraceableEventDispatcher))
        in /home/aien/Web/MrAlef/MRA/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php line 61

    at Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke(object(GetResponseEvent), 'kernel.request', object(ContainerAwareEventDispatcher))
        in  line 

    at call_user_func(object(WrappedListener), object(GetResponseEvent), 'kernel.request', object(ContainerAwareEventDispatcher))
        in /home/aien/Web/MrAlef/MRA/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php line 184

    at Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(array(object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener)), 'kernel.request', object(GetResponseEvent))
        in /home/aien/Web/MrAlef/MRA/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php line 46

    at Symfony\Component\EventDispatcher\EventDispatcher->dispatch('kernel.request', object(GetResponseEvent))
        in /home/aien/Web/MrAlef/MRA/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php line 140

    at Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch('kernel.request', object(GetResponseEvent))
        in /home/aien/Web/MrAlef/MRA/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php line 125

    at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1')
        in /home/aien/Web/MrAlef/MRA/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php line 64

    at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true)
        in /home/aien/Web/MrAlef/MRA/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/DependencyInjection/ContainerAwareHttpKernel.php line 69

    at Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(object(Request), '1', true)
        in /home/aien/Web/MrAlef/MRA/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php line 185

    at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
        in /home/aien/Web/MrAlef/MRA/web/app_dev.php line 30

new release

Hi,

Can you tag a new release? With the current stable i'm unable to upgrade Symfony:

472 !!  PHP Fatal error:  Uncaught ArgumentCountError: Too few arguments to function Symfony\Component\Config\Definition\Builder\TreeBuilder::__construct(), 0 passed in /srv/api/vendor/auth0/jwt-auth-bundle/src/DependencyInjection/Configuration.php on line 20 and at least 1 expected in /srv/api/vendor/symfony/config/Definition/Builder/TreeBuilder.php:26
473 !!  Stack trace:
474 !!  #0 /srv/api/vendor/auth0/jwt-auth-bundle/src/DependencyInjection/Configuration.php(20): Symfony\Component\Config\Definition\Builder\TreeBuilder->__construct()
475 !!  #1 /srv/api/vendor/symfony/config/Definition/Processor.php(50): Auth0\JWTAuthBundle\DependencyInjection\Configuration->getConfigTreeBuilder()
476 !!  #2 /srv/api/vendor/symfony/dependency-injection/Extension/Extension.php(106): Symfony\Component\Config\Definition\Processor->processConfiguration()
477 !!  #3 /srv/api/vendor/auth0/jwt-auth-bundle/src/DependencyInjection/JWTAuthExtension.php(19): Symfony\Component\DependencyInjection\Extension\Extension->processConfiguration()
478 !!  #4 /srv/api/vendor/symfony/dependency-injection/Compiler/Me in /srv/api/vendor/symfony/config/Definition/Builder/TreeBuilder.php on line 26
479 !!  
480 Script @auto-scripts was called via post-install-cmd

This is fixed in #79

... but is not mandatory

Hello there !

Any example to use this bundle without auth0 use ?

Maybe using FOSUser bundle ?

Thanks !

Support Symfony4

Are there any plans to support sf4 in the near future? This is like a real blocker (for me) to use Auth0 in the future.

PHP version on 5.x branches

Describe the problem

5.x branches require PHP version ^8.0 but Symfony 6.1 packages require >=8.1.

What was the expected behavior?

Installing a 5.x branch should require PHP >=8.1

Reproduction

composer require auth0/jwt-auth-bundle:5.0.0-BETA1

Environment

PHP 8.0

CSRF invalid with support true

Describe the problem

Having support return true on the Authenticator messes up CSRF tokens.

I just installed a fresh SF 6.2 EasyAdmin 4 setup and integrated this bundle.
Every time we want to do a form operation we get a CSRF token invalid message.

What was the expected behavior?

Don't change the token on every request.

Having the support trigger only on the callback route seems to fix this.

Inconsistent install instructions for master branch

Could you please provide some useful install instructions for the master branch. There is written that you should install this bundle like this:

composer require auth0/jwt-auth-bundle:"~3.0"

but the configuration underneath is not fitting to the configuration required for branch ~3.0

also the master branch is not ~3.0, it is ~4.0...

It would be really nice to provide at least one single example demo project which is pointing to the right direction.

Thank you very much

Support for Symfony LTS versions

Hi,

Thanks for the release! It's a great new! I have been tracking this repo for months looking for a new release compatible with Symfony 5.4. Today was released the new version 5.0.0 but only compatible from Symfony 6.1+. Previous version 4.0.0 was not compatible with Symfony 5.4 (many deprecation warnings) because the old authenticator format.

Taking a look to #130 one of main goal it's support for 5.1+ versions (and also for 6+) but in composer.json (and Readme) the minimal required version it's 6.1.

It's possible to consider adapt code for this Long Term Support version of Symfony?

Thanks for your effort and your work.

Please release a stable version 5

Hi, thanks for maintaining this package!

auth0/php-jwt has recently been abandoned and triggers an error every time you run composer update. It is part of the last stable version of this bundle.
Could you please release a stable version 5, so we can move away from the abandoned package?

Thanks if you have the time :)

Dependencies conflict

Package conflict

We are using V4.0.0 of this package and also using the https://github.com/symfony /
mercure-bundle

auth0/jwt-auth-bundle uses V7 of auth0/auth0-php, which uses a fork of lcobucci/jwt package, with same namespace but added breaking changes.
mercure bundle use the original lcobucci/jwt package

see this issue

Resolution

There is a simple way to resolve the problem, since auth0/jwt-auth-bundle *V8 address that exact problem. By upgrading your dependencies on auth0/jwt-auth-bundle to V8 you will solve it.

Setting secret_base64_encoded as false causes an exception

In the jwt_auth configuration block setting secret_base64_encoded to false throws a InvalidConfigurationException with the message

The path "jwt_auth.secret_base64_encoded" cannot contain an empty value, but got false.

Since the default is true, this means I can't set secret_base64_encoded to be false.

Add support for symfony/framework-bundle:^6.0

Describe the problem you'd like to have solved

We are using this bundle yet we cannot upgrade to Symfony 6.0 because this bundle only supports symfony/framework-bundle: ^4.4 || ~5.1.

Likewise, it would not be possible to use this bundle on any new project starting up with Symfony 6 (which is publicly available for over 3 months now)

Describe the ideal solution

Considering that Symfony 5.4 is supported, upgrading to 6.0 should be only the cleanup of deprecations and update in composer.json.
One possible issue could be the Security component and the new Authenticator system, but I see there is an open PR here #121 that solves exactly that problem (it's just a little quite there somehow).

Alternatives and current work-arounds

N/A

Additional information, if any

N/A

Give us a way to specify cache when the JWTVerifier is created

The Auth0Service uses JWTVerifier from the auth0-PHP SDK. auth0-PHP allows specifying a cache which will greatly speed up requests to the Auth0Service. I am currently experience a 3000 millisecond response time for every request that uses the Auth0Service. I manually changed the Auth0Service to use cache and the response time has gone back down to a reasonable 300 milliseconds.

Support new Authenticator system

In SF 5.1, a new Authenticator-based security system was introduced as an experimental feature. With SF 5.3 released (today), the Guard system is deprecated whilst the new Authenticator system is marked stable and will be set as the default for SF 6.0.

Upgrading to SF 5.3 results leads to the following deprecation notice:

The "Auth0\JWTAuthBundle\Security\Guard\JwtGuardAuthenticator" class extends "Symfony\Component\Security\Guard\AbstractGuardAuthenticator" that is deprecated since Symfony 5.3, use the new authenticator system instead.

Would be great if the new authenticator system can be supported.

More reading material here:
https://symfony.com/blog/new-in-symfony-5-3-guard-component-deprecation
https://symfony.com/doc/current/security/experimental_authenticators.html
https://symfony.com/doc/current/security/experimental_authenticators.html#creating-a-custom-authenticator

decode call uses invalid arguments

Since this commit was merged it looks to me like Auth0Service::decodeJWT will pass an invalid argument:

return Auth0JWT::decode($encToken, $this->client_id, $this->client_secret, $this->secret_base64_encoded);

but the decode method expects

public static function decode($jwt, $valid_audiences, $client_secret, array $authorized_iss = [])

which results in:
Type error: Argument 4 passed to Auth0\\SDK\\Auth0JWT::decode() must be of the type array, boolean given

Use interfaces to allow decoration

Describe the problem you'd like to have solved

At this moment we can't decorate parts of the bundle.
My use case is that I would like to add the user to my own database to control more there.
For that I need to plug in to the Authenticator.

For ex. In the AuthenticationController we use a Authenticator but we should use the AuthenticatorInterface.

Describe the ideal solution

Use the contracts everywhere we can to enable proper decoration.

This could allow a decorated Controller for example:

<?php

namespace App\Controller;

use App\Security\DecoratingAuthenticator;
use Auth0\SDK\Auth0;
use Auth0\Symfony\Contracts\Controllers\AuthenticationControllerInterface;
use Auth0\Symfony\Controllers\AuthenticationController;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\Attribute\AsDecorator;
use Symfony\Component\DependencyInjection\Attribute\MapDecorated;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\RouterInterface;

#[AsDecorator(decorates: AuthenticationController::class)]
class DecoratingAuthenticationController extends AbstractController implements AuthenticationControllerInterface
{
    private AuthenticationController $inner;

    public function __construct(
        #[MapDecorated] AuthenticationController $inner,
        private readonly RouterInterface $router,
        private readonly DecoratingAuthenticator $authenticator
    ) {
        $this->inner = $inner;
    }

    public function login(Request $request): Response
    {
        return $this->inner->login($request);
    }

    public function logout(Request $request): Response
    {
        return $this->inner->logout($request);
    }

    public function callback(Request $request): Response
    {
        return $this->inner->callback($request);
    }

    protected function getRedirectUrl(string $route): string
    {
       $routes = $this->authenticator->configuration['routes'] ?? [];
        $configuredRoute = $routes[$route] ?? null;

        if (null !== $configuredRoute && '' !== $configuredRoute) {
            try {
                return $this->router->generate($configuredRoute);
            } catch (\Throwable $th) {
            }
        }

        return '';
    }

    protected function getSdk(): Auth0
    {
        return $this->authenticator->getInner()->service->getSdk();
    }
}
<?php

namespace App\Security;

use Auth0\Symfony\Security\Authenticator;
use Symfony\Component\DependencyInjection\Attribute\AsDecorator;
use Symfony\Component\DependencyInjection\Attribute\MapDecorated;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface;
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport;

#[AsDecorator(decorates: 'auth0.authenticator')]
readonly class DecoratingAuthenticator implements AuthenticatorInterface
{
    private Authenticator $inner;
    public function __construct(#[MapDecorated] Authenticator $inner)
    {
        $this->inner = $inner;
    }

    /**
     * @throws \JsonException
     */
    public function authenticate(Request $request): Passport
    {
        $session = ($sdk = $this->inner->service->getSdk()) ? $sdk->getCredentials() : null;

        if (null === $session) {
            throw new CustomUserMessageAuthenticationException('No Auth0 session was found.');
        }

        $user = json_encode(['type' => 'stateful', 'data' => $session], JSON_THROW_ON_ERROR);

        return new SelfValidatingPassport(
            new UserBadge($user, function () use ($user, $sdk) {
                $auth0User = $sdk->getUser();
                
                // Do custom action to save users locally, trigger events, ...

                return $user;
            })
        );
    }

    public function supports(Request $request): ?bool
    {
        return $this->inner->supports($request);
    }

    public function createToken(Passport $passport, string $firewallName): TokenInterface
    {
        return $this->inner->createToken($passport, $firewallName);
    }

    public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response
    {
        return $this->inner->onAuthenticationSuccess($request, $token, $firewallName);
    }

    public function onAuthenticationFailure(Request $request, AuthenticationException $exception): ?Response
    {
        return $this->inner->onAuthenticationFailure($request, $exception);
    }

    public function getInner(): Authenticator
    {
        return $this->inner;
    }
}

500 on expired token

JWT::decode can throw ExpiredException, but any exception is converted to CoreException at JWTVerifier->verifyAndDecode.
So CoreException is throwed to Auth0Service->decodeJWT and it is not catched anywhere, what means 500 for Users Application.

To fix it - we need to create internal ExpiredException and use it for expired token and transform it to AuthenticationException, catch it with built-in AuthenticationFailureHandlerInterface and throw 401 code according to https://stackoverflow.com/questions/8855297/token-expired-json-rest-api-error-code

Full stack trace:
image

Links to examples in documentation are broken

Describe the problem

In the Readme, the link to "Symfony API Samples" and the link to "example code" lead to a 404 page.

What was the expected behavior?

Links bringing me to the code samples, which would be important for new users.

Reproduction

Just click the links on the home page of the repository.

Environment

  • master branch
  • Version of this library used:
  • Which framework are you using, if applicable:
  • Other modules/plugins/libraries that might be involved:
  • Any other relevant information you think would be useful:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.