composer require pirabyte/lexwareoffice-socialiteAdd the following to your services.php,
'lexwareoffice' => [
'url' => env('LEXWARE_OFFICE_URL', 'https://sandbox.example.com'),
'api' => env('LEXWARE_OFFICE_API', 'https://api.sandbox.example.com'),
'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_URLLEXWARE_OFFICE_APILEXWARE_OFFICE_CLIENT_IDLEXWARE_OFFICE_CLIENT_SECRETLEXWARE_OFFICE_REDIRECT_URL
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');
}