DocCheck Login Provider for Laravel Socialite
antwerpes/socialite-doccheck is a Laravel package for doccheck login provider for laravel socialite.
It currently has 1 GitHub stars and 69 downloads on Packagist (latest version 2.0.0).
Install it with composer require antwerpes/socialite-doccheck.
Discover more Laravel packages by antwerpes
or browse all Laravel packages to compare alternatives.
Last updated
Laravel Socialite provider for the DocCheck Login. Compatible with both economy and business licenses.
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'),
],
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('/');
}
}
You can either render the DocCheck Login button with the DocCheck Web Component or pass the Login URL directly to a Blade template.
If you want to pass the generated URL directly:
public function showLoginForm(): Response
{
$url = Socialite::driver('doccheck')->redirect()->getTargetUrl();
return response()->view('auth.login', [
'url' => $url,
]);
}
Blade Template:
<a href="{{ $url }}">Login with DocCheck</a>
If you want to render the Login with DocCheck Button using the Web Component, also extract and pass the state parameter:
public function showLoginForm(): Response
{
$url = Socialite::driver('doccheck')->redirect()->getTargetUrl();
$state = null;
$query = parse_url($url, PHP_URL_QUERY);
if (is_string($query)) {
parse_str($query, $params);
$state = $params['state'] ?? null;
}
return response()->view('auth.login', [
'url' => $url,
'state' => $state,
]);
}
Blade example (DocCheck Web Component):
<script src="[latest main.js]"></script>
<dc-login-button
size="medium"
language="en"
loginClientId="{{ config('services.doccheck.client_id') }}"
redirectUri="{{ config('services.doccheck.redirect') }}"
scope="unique_id profession country language"
state="{{ $state }}"
></dc-login-button>
The callback logic stays the same (see example above).
Please see CHANGELOG for more information on what has changed recently.
Contributions are welcome! Leave an issue on GitHub, or create a Pull Request.
The MIT License (MIT). Please see License File for more information.