Download the PHP package renoki-co/hej without Composer
On this page you can find all versions of the php package renoki-co/hej. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download renoki-co/hej
More information about renoki-co/hej
Files in renoki-co/hej
Informations about the package hej
Hej! - a Socialite authentication flow implementation
Hej! is a simple authentication flow implementation for Socialite. Out-of-the-box, Hej! can help you login and register users using Socialite providers, or link and unlink social accounts, just by extending a controller.
- Hej! - a Socialite authentication flow implementation
- 🤝 Supporting
- 🚀 Installation
- 🙌 Usage
- Extending Controllers
- Provider whitelisting
- Custom Socialite Redirect & Retrieval
- Registering new users
- Handling duplicated E-Mail addresses
- Filling the Social table
- Callbacks
- Redirects
- Link & Unlink
- Custom Authenticatable
- 🐛 Testing
- 🤝 Contributing
- 🔒 Security
- 🎉 Credits
🤝 Supporting
If you are using one or more Renoki Co. open-source packages in your production apps, in presentation demos, hobby projects, school projects or so, sponsor our work with Github Sponsors. 📦
🚀 Installation
You can install the package via composer:
Publish the config:
Publish the migrations:
🙌 Usage
For the user (or any Authenticatable instance) you should add the HasSocialAccounts
trait and the Sociable
interface:
Out-of-the-box, it works with any Laravel application.
After you have configured Socialite, the only thing to do is to point your desired redirect and callback paths to the package controller:
The paths can be any, as long as they contain a first parameter which is going to be the provider you try to authenticate with. For example, accessing this link will redirect to Github:
Extending Controllers
Hej! is really flexible and does a lot of things in the background to register or login using Socialite.
However, you need to extend the controller and you will then be able to replace some methods to customize the flow.
Then you should point the routes to the new controller.
Provider whitelisting
Due to the fact that the endpoints are opened to get any provider, you can whitelist the Socialite provider names that can be used:
For example, allowing only Facebook and Github should look like this:
If one of the providers accessed via the URL is not whitelisted, a simple redirect is done automatically. However, you can replace it and redirect to your custom redirect action.
Custom Socialite Redirect & Retrieval
With Socialite, you can use ->redirect()
to redirect the user and ->user()
to retrieve it. You can customize the instances by replacing getSocialiteRedirect
and getSocialiteUser
.
Here is the default configuration:
Registering new users
When the Social account that the user logged in is not registered within the database, it creates a new authenticatable model, but in order to do this, it should fill it with data.
By default, it fills in using Socialite Provider's given data and sets a random 64-letter word password:
Handling duplicated E-Mail addresses
Sometimes, it can happen for the users to have an account created with E-Mail address only, having no social accounts. A new social account with the same E-Mail address will trigger a new authenticatable record in the database on callback.
For this, a Redirect is made to handle this specific scenario.
Filling the Social table
After registration or login, the Socialite data gets created or updated, either the user existed or not.
By default, it's recommended to not get overwritten, excepting for the fact you want to change the table structure and extend the Social
model that is also set in config/hej.php
.
Callbacks
Right before the user is authenticated or registered successfully, there exist callback that trigger and you can replace them for some custom logic.
Redirects
You are free to overwrite the actions' redirects within the controller:
Link & Unlink
Prior to creating new accounts or logging in with Socialite providers, Hej! comes with support to link and unlink Social accounts to and from your users.
You will need to have the routes accessible only for your authenticated users:
Further, you may access the URLs to link or unlink providers.
Additionally, you may implement custom redirect for various events happening during link/unlink:
Custom Authenticatable
When trying to login or register, the package uses the default App\User
as defined in config/hej.php
. However, this can easily be replaced at the request level:
For example, you can change the model to authenticate as for different Socialite providers:
Keep in mind that the model should also use the Trait and the Interface and be Authenticatable
.
🐛 Testing
🤝 Contributing
Please see CONTRIBUTING for details.
🔒 Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
🎉 Credits
- Alex Renoki
- All Contributors
All versions of hej with dependencies
illuminate/support Version ^9.0.1
laravel/socialite Version ^5.3