Download the PHP package sensiolabs/connect-bundle without Composer
On this page you can find all versions of the php package sensiolabs/connect-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sensiolabs/connect-bundle
More information about sensiolabs/connect-bundle
Files in sensiolabs/connect-bundle
Package connect-bundle
Short Description Official bundle for the SymfonyConnect SDK
License MIT
Homepage https://github.com/symfonycorp/connect-bundle
Informations about the package connect-bundle
symfony/connect-bundle
About
This is the official bundle of the SymfonyConnect SDK.
Installation
Step 1: Install symfony/connect-bundle using Composer
If you're not using Symfony Flex, please take inspiration from this bundle's recipe to enable it.
Step 2: Configure your .env.local
file
Usage
Use SymfonyConnect to authenticate your user
Step 1: Configure the security
Note: If you want to persist your users, read the Cookbooks section.
If you don't want to persist your users, you can use ConnectInMemoryUserProvider
:
You can also load specific roles for some users:
Note: The username
is the user uuid.
Step 2: Add some link to your templates
You can generate a link to the SymfonyConnect login page:
You can also specify the target URL after connection:
Step 3: Play with the user
The API user is available through the token storage, which you can get by autowiring
Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface $tokenStorage
.
If you use the built-in security component, you can access to the root api
directly by autowiring SymfonyCorp\Connect\Api\Api $api
:
You can also get access to the API root object by providing an access token explicitly:
Step 4: Handling Failures
Several errors can occur during the OAuth dance, for example the user can
deny your application or the scope you defined in symfony_connect.yaml
can be different
from what you selected while creating your application on SymfonyConnect.
Theses failures arehandled by the default Symfony failure handling.
Therefore, if an error occurred, the error is stored in the session (with a
fallback on query attributes) and the user is redirected to the route/path
specificed in failure_path
node of the symfony_connect
section of your
firewall in security.yaml
.
Warning: You need to specifiy
failure_path
. If you don't, the user will be redirected back tologin_path
, meaning that will launch the SymfonyConnect authentication and redirect the user to SymfonyConnect which can lead to a redirection loop.
This means you need to fetch the authentication error if there is one and display
it in the view. This is similar to what you do for a typical login form on
Symfony (here we assume you have a home
route pointing to the following controller):
And then adapt your twig template:
Cookbooks
How to persist users
Step 1 - Create a User
entity
Step 2 - Create the repository
Don't forget to update your database.
Step 3 - Create the event listener
Step 4 - Configure security
Step 5 - Enjoy
You can store more things if you want. But don't forget to update your application scope.
License
This bundle is licensed under the MIT license.