antwerpes/socialite-doccheck
最新稳定版本:1.0.0
Composer 安装命令:
composer require antwerpes/socialite-doccheck
包简介
DocCheck Login Provider for Laravel Socialite
README 文档
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.
统计信息
- 总下载量: 49
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-06-27