pirabyte / lexwareoffice-socialite
Lexware Office OAuth2 Provider for Laravel Socialite
v0.0.1
2025-02-06 13:28 UTC
Requires
- php: ^8.2
- ext-json: *
- socialiteproviders/manager: ^4.4
README
composer require pirabyte/lexwareoffice-socialite
Add the following to your services.php
,
'lexwareoffice' => [ 'url' => env('LEXWARE_OFFICE_URL', 'https://lexoffice-sandbox.grld.eu'), 'api' => env('LEXWARE_OFFICE_API', 'https://api-sandbox.grld.eu'), 'client_id' => env('LEXWARE_OFFICE_CLIENT_ID'), 'client_secret' => env('LEXWARE_OFFICE_CLIENT_SECRET'), 'redirect' => env('LEXWARE_OFFICE_REDIRECT_URL'), ],
In app/Providers/AppServiceProvider.php
add the following listener to the SocialiteWasCalled
event:
Event::listen(function (SocialiteWasCalled $event) { $event->extendSocialite('lexwareoffice', \Pirabyte\Socialite\LexwareOffice\Provider::class); });
For Laravel < 11, add it to your
EventServiceProvider.php
.
Make sure you have the corresponding .env
keys present:
LEXWARE_OFFICE_URL
LEXWARE_OFFICE_API
LEXWARE_OFFICE_CLIENT_ID
LEXWARE_OFFICE_CLIENT_SECRET
LEXWARE_OFFICE_REDIRECT_URL
How to use
In your controller create a new method
public function redirect() { return Socialite::driver('lexwareoffice')->redirect(); }
This will redirect to lexware office to start the OAuth2.0 Flow.
Add another method to catch the response
public function callback(): \Illuminate\Http\RedirectResponse { $connection = Socialite::driver('lexwareoffice')->user(); $user = request()->user(); LexwareOfficeClient::updateOrCreate([ 'user_id' => $user->id, ], [ 'access_token' => $connection->token, 'refresh_token' => $connection->refreshToken, 'expires_at' => Carbon::now()->addSeconds($connection->expiresIn), ]); return redirect()->route('dashboard'); }