Download the PHP package lbausch/flarum-laravel-session without Composer
On this page you can find all versions of the php package lbausch/flarum-laravel-session. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package flarum-laravel-session
Flarum Laravel Session
- What It Does
- Requirements
- Installation and Configuration
- Composer
- Register Middleware
- Setup Database Connection
- Publish Package Configuration
- Disable Cookie Encryption
- Usage
- Setup Middleware
- Handle An Identified User
- Accessing Flarum Session Cookie From Different Domain
What It Does
This package allows to use the session of Flarum for authentication within a Laravel application. It accesses Flarum's session cookie and reads the session data from the session storage. Based on the user information in the Flarum user database an user in the Laravel application is created / updated and logged in.
Requirements
- PHP 8.1+
- Laravel 10
- Working installation of Flarum in the same filesystem as the Laravel application, so Flarum's session files can be read
- Flarum and Laravel need to share the same domain / subdomain, so Flarum's session cookie can be accessed
Installation and Configuration
Composer
Install the package with Composer:
Register Middleware
Register the \Bausch\FlarumLaravelSession\FlarumSessionMiddleware
middleware in app/Http/Kernel.php
:
Setup Database Connection
Define a database connection for the Flarum database in config/database.php
:
Publish Package Configuration
Publish the package configuration using php artisan vendor:publish --provider=Bausch\\FlarumLaravelSession\\ServiceProvider
and update config/flarum.php
with your settings.
Disable Cookie Encryption
To avoid Laravel from trying to encrypt the Flarum session cookie, add the following to app/Http/Middleware/EncryptCookies.php
:
Usage
Setup Middleware
In routes/web.php
you may assign the middleware as desired:
All requests to the /
route will then be checked by the middleware.
Handle An Identified User
Once the middleware successfully identified an user, it executes the default handler \Bausch\FlarumLaravelSession\Actions\HandleIdentifiedUser
. You may configure a different handler by calling FlarumLaravelSession::handleIdentifiedUser()
in a service provider. This is a perfect place to update attributes or execute further actions, just remember to implement the \Bausch\FlarumLaravelSession\Contracts\FlarumUserIdentified
interface.
Have a look at the default handler for a reference implementation.
If you need to use a different user model than App\Models\User
, you may call FlarumLaravelSession::useUserModel(YourUser::class)
in your service provider.
Accessing Flarum Session Cookie From Different Domain
If Flarum is running on domain.tld and Laravel on sub.domain.tld you need to configure Flarum (config.php
), so the session cookie can be accessed on the subdomain:
All versions of flarum-laravel-session with dependencies
illuminate/auth Version ^10.0
illuminate/filesystem Version ^10.0
illuminate/http Version ^10.0
illuminate/session Version ^10.0
illuminate/support Version ^10.0