antwerpes / socialite-doccheck
DocCheck Login Provider for Laravel Socialite
Requires
- php: ^8.0|^8.1|^8.2
- ext-json: *
- illuminate/contracts: ^9.28|^10.0
- laravel/socialite: ~5.0
Requires (Dev)
- chiiya/laravel-code-style: ^2.2
- orchestra/testbench: ^6.0|^7.1|^8.0
This package is auto-updated.
Last update: 2024-12-09 03:02:34 UTC
README
Laravel Socialite provider for the DocCheck Login. Compatible with both economy and business licenses.
Installation
You can install the package via composer:
composer require antwerpes/socialite-doccheck
Update your services configuration (config/services.php
) with the following entry:
'doccheck' => [ 'client_id' => env('DOCCHECK_CLIENT_KEY'), 'client_secret' => env('DOCCHECK_CLIENT_SECRET'), 'redirect' => env('DOCCHECK_REDIRECT_URI'), 'language' => env('DOCCHECK_LANGUAGE', 'de'), 'template' => env('DOCCHECK_TEMPLATE', 'fullscreen_dc'), 'license' => env('DOCCHECK_LICENSE', 'economy'), ],
Usage
After setting up the environment variables (see configuration above), you may use this provider as any
other Socialite provider, see also Socialite documentation.
The user object returned by the provider differs by license. For the economy
license, only an ID
will be present. For the business
license all other fields will also be present.
Example code:
<?php use Illuminate\Http\Request; use Illuminate\Routing\Controller; use Laravel\Socialite\Facades\Socialite; class LoginController extends Controller { public function handleProviderCallback(Request $request) { $details = Socialite::driver('doccheck')->user(); $user = User::query() ->firstOrNew([ 'id' => $details->getId(), ]) // Only available with the `business` license ->fill([ 'email' => $details->getEmail(), 'first_name' => $details->first_name, 'last_name' => $details->last_name, 'title' => $details->title, 'street' => $details->street, 'postal_code' => $details->street, 'city' => $details->city, 'country' => $details->country, 'language' => $details->language, 'gender' => $details->gender, 'profession_id' => $details->profession_id, 'discipline_id' => $details->discipline_id, ]); $user->save(); auth()->login($user); return redirect()->intended('/'); } }
Login via iFrame
To embed the login on your website instead of relying on redirects, make sure you use a valid iFrame template first
(e.g. login_xl
). Next, in your controller, instead of redirecting the user, grab the constructed redirect URL and
pass it to your view:
public function showLoginForm(): Response { $url = Socialite::driver('doccheck')->redirect()->getTargetUrl(); return response()->view('auth.login', [ 'url' => $url, ]); }
In your view you can then simply embed the iFrame using the embedding code given to you, but replacing the url with the one we just generated, for example:
<iframe align="left" frameborder="0" width="467" height="231" name="dc_login_iframe" id="dc_login_iframe" src="{{ $url }}" > <a href="{{ $url }}" target="_blank">LOGIN</a> </iframe>
The callback logic stays the same (see example above).
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Contributions are welcome! Leave an issue on GitHub, or create a Pull Request.
License
The MIT License (MIT). Please see License File for more information.