mirror of
https://github.com/bs-community/blessing-skin-plugins.git
synced 2025-01-07 03:06:43 +08:00
add oauth client as plugin
This commit is contained in:
parent
ae7b46572b
commit
46e6ed474d
@ -10,3 +10,6 @@ insert_final_newline = true
|
||||
|
||||
[*.{php,ps1}]
|
||||
indent_size = 4
|
||||
|
||||
[composer.json]
|
||||
indent_size = 4
|
||||
|
@ -1,8 +1,10 @@
|
||||
<?php
|
||||
|
||||
use Blessing\Filter;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
return function (Dispatcher $events) {
|
||||
return function (Dispatcher $events, Filter $filter) {
|
||||
$events->listen(
|
||||
'SocialiteProviders\Manager\SocialiteWasCalled',
|
||||
'SocialiteProviders\GitHub\GitHubExtendSocialite@handle'
|
||||
@ -14,6 +16,12 @@ return function (Dispatcher $events) {
|
||||
'redirect' => env('GITHUB_REDIRECT_URI'),
|
||||
]]);
|
||||
|
||||
resolve('oauth.providers')
|
||||
->put('github', ['icon' => 'github', 'displayName' => 'GitHub']);
|
||||
$filter->add('oauth_providers', function (Collection $providers) {
|
||||
$providers->put('github', [
|
||||
'icon' => 'github',
|
||||
'displayName' => 'GitHub',
|
||||
]);
|
||||
|
||||
return $providers;
|
||||
});
|
||||
};
|
||||
|
2
oauth-github/lang/en/general.yml
Normal file
2
oauth-github/lang/en/general.yml
Normal file
@ -0,0 +1,2 @@
|
||||
title: Log In with GitHub
|
||||
description: Log in skin server with GitHub.
|
2
oauth-github/lang/zh_CN/general.yml
Normal file
2
oauth-github/lang/zh_CN/general.yml
Normal file
@ -0,0 +1,2 @@
|
||||
title: 使用 GitHub 登录
|
||||
description: 用 GitHub 账号来登录皮肤站
|
@ -1,13 +1,14 @@
|
||||
{
|
||||
"name": "oauth-github",
|
||||
"title": "使用 GitHub 登录",
|
||||
"version": "0.1.4",
|
||||
"description": "用 GitHub 账号来登录皮肤站",
|
||||
"title": "Blessing\\OAuth\\GitHub::general.title",
|
||||
"version": "0.2.0",
|
||||
"description": "Blessing\\OAuth\\GitHub::general.description",
|
||||
"author": "GPlane",
|
||||
"url": "https://gplane.win/",
|
||||
"namespace": "Blessing\\OAuth\\GitHub",
|
||||
"require": {
|
||||
"blessing-skin-server": "^5.0.0"
|
||||
"blessing-skin-server": "^5.0.0",
|
||||
"oauth": "^1.0.0"
|
||||
},
|
||||
"enchants": {
|
||||
"icon": {
|
||||
|
@ -1,8 +1,10 @@
|
||||
<?php
|
||||
|
||||
use Blessing\Filter;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
return function (Dispatcher $events) {
|
||||
return function (Dispatcher $events, Filter $filter) {
|
||||
$events->listen(
|
||||
'SocialiteProviders\Manager\SocialiteWasCalled',
|
||||
'BlessingSocialiteProviders\LittleSkin\LittleSkinExtendSocialite@handle'
|
||||
@ -14,6 +16,12 @@ return function (Dispatcher $events) {
|
||||
'redirect' => env('LITTLESKIN_REDIRECT_URI'),
|
||||
]]);
|
||||
|
||||
resolve('oauth.providers')
|
||||
->put('littleskin', ['icon' => 'littleskin', 'displayName' => 'LittleSkin']);
|
||||
$filter->add('oauth_providers', function (Collection $providers) {
|
||||
$providers->put('littleskin', [
|
||||
'icon' => 'littleskin',
|
||||
'displayName' => 'LittleSkin',
|
||||
]);
|
||||
|
||||
return $providers;
|
||||
});
|
||||
};
|
||||
|
2
oauth-littleskin/lang/en/general.yml
Normal file
2
oauth-littleskin/lang/en/general.yml
Normal file
@ -0,0 +1,2 @@
|
||||
title: Log In with LittleSkin
|
||||
description: Log in skin server with LittleSkin account.
|
2
oauth-littleskin/lang/zh_CN/general.yml
Normal file
2
oauth-littleskin/lang/zh_CN/general.yml
Normal file
@ -0,0 +1,2 @@
|
||||
title: 使用 LittleSkin 登录
|
||||
description: 用 LittleSkin 账号来登录皮肤站
|
@ -1,13 +1,14 @@
|
||||
{
|
||||
"name": "oauth-littleskin",
|
||||
"title": "使用 LittleSkin 登录",
|
||||
"version": "0.1.5",
|
||||
"description": "用 LittleSkin 账号来登录皮肤站",
|
||||
"title": "Blessing\\OAuth\\LittleSkin::general.title",
|
||||
"version": "0.2.0",
|
||||
"description": "Blessing\\OAuth\\LittleSkin::general.description",
|
||||
"author": "Asnxthaony",
|
||||
"url": "https://github.com/Asnxthaony",
|
||||
"namespace": "Blessing\\OAuth\\LittleSkin",
|
||||
"require": {
|
||||
"blessing-skin-server": "^5.0.0"
|
||||
"blessing-skin-server": "^5.0.0",
|
||||
"oauth": "^1.0.0"
|
||||
},
|
||||
"enchants": {
|
||||
"icon": {
|
||||
|
@ -1,8 +1,10 @@
|
||||
<?php
|
||||
|
||||
use Blessing\Filter;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
return function (Dispatcher $events) {
|
||||
return function (Dispatcher $events, Filter $filter) {
|
||||
$events->listen(
|
||||
'SocialiteProviders\Manager\SocialiteWasCalled',
|
||||
'SocialiteProviders\Live\LiveExtendSocialite@handle'
|
||||
@ -14,6 +16,12 @@ return function (Dispatcher $events) {
|
||||
'redirect' => env('LIVE_REDIRECT_URI'),
|
||||
]]);
|
||||
|
||||
resolve('oauth.providers')
|
||||
->put('live', ['icon' => 'microsoft', 'displayName' => 'Microsoft Live']);
|
||||
$filter->add('oauth_providers', function (Collection $providers) {
|
||||
$providers->put('littleskin', [
|
||||
'icon' => 'microsoft',
|
||||
'displayName' => 'Microsoft Live',
|
||||
]);
|
||||
|
||||
return $providers;
|
||||
});
|
||||
};
|
||||
|
2
oauth-microsoft-live/lang/en/general.yml
Normal file
2
oauth-microsoft-live/lang/en/general.yml
Normal file
@ -0,0 +1,2 @@
|
||||
title: Log In with Microsoft Live
|
||||
description: Log in skin server with Microsoft Live.
|
2
oauth-microsoft-live/lang/zh_CN/general.yml
Normal file
2
oauth-microsoft-live/lang/zh_CN/general.yml
Normal file
@ -0,0 +1,2 @@
|
||||
title: 使用 Microsoft Live 登录
|
||||
description: 通过 Microsoft Live 来登录皮肤站
|
@ -1,13 +1,14 @@
|
||||
{
|
||||
"name": "oauth-microsoft-live",
|
||||
"title": "使用 Microsoft Live 登录",
|
||||
"version": "0.1.4",
|
||||
"description": "通过 Microsoft Live 来登录皮肤站",
|
||||
"title": "Blessing\\OAuth\\Live::general.title",
|
||||
"version": "0.2.0",
|
||||
"description": "Blessing\\OAuth\\Live::general.description",
|
||||
"author": "GPlane",
|
||||
"url": "",
|
||||
"namespace": "Blessing\\OAuth\\Live",
|
||||
"require": {
|
||||
"blessing-skin-server": "^5.0.0"
|
||||
"blessing-skin-server": "^5.0.0",
|
||||
"oauth": "^1.0.0"
|
||||
},
|
||||
"enchants": {
|
||||
"icon": {
|
||||
|
35
oauth/bootstrap.php
Normal file
35
oauth/bootstrap.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use App\Services\Hook;
|
||||
use Blessing\Filter;
|
||||
use Illuminate\Support\Facades\View;
|
||||
|
||||
return function (Filter $filter) {
|
||||
View::composer('Blessing\OAuthCore::providers', function ($view) use ($filter) {
|
||||
$providers = $filter->apply('oauth_providers', collect());
|
||||
|
||||
$view->with('providers', $providers);
|
||||
});
|
||||
|
||||
$filter->add('auth_page_rows:login', function ($rows) {
|
||||
$length = count($rows);
|
||||
array_splice($rows, $length - 1, 0, ['Blessing\OAuthCore::providers']);
|
||||
|
||||
return $rows;
|
||||
});
|
||||
|
||||
$filter->add('auth_page_rows:register', function ($rows) {
|
||||
$rows[] = 'Blessing\OAuthCore::providers';
|
||||
|
||||
return $rows;
|
||||
});
|
||||
|
||||
Hook::addRoute(function () {
|
||||
Route::prefix('auth/login')
|
||||
->namespace('Blessing\OAuthCore')
|
||||
->group(function () {
|
||||
Route::get('{driver}', 'AuthController@login');
|
||||
Route::get('{driver}/callback', 'AuthController@callback');
|
||||
});
|
||||
});
|
||||
};
|
5
oauth/composer.json
Normal file
5
oauth/composer.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"require": {
|
||||
"socialiteproviders/manager": "^3.5"
|
||||
}
|
||||
}
|
2
oauth/lang/en/general.yml
Normal file
2
oauth/lang/en/general.yml
Normal file
@ -0,0 +1,2 @@
|
||||
title: OAuth Client Core
|
||||
description: Core plugin of OAuth client.
|
1
oauth/lang/en/providers.yml
Normal file
1
oauth/lang/en/providers.yml
Normal file
@ -0,0 +1 @@
|
||||
title: Log In with
|
2
oauth/lang/zh_CN/general.yml
Normal file
2
oauth/lang/zh_CN/general.yml
Normal file
@ -0,0 +1,2 @@
|
||||
title: OAuth 客户端核心
|
||||
description: OAuth 客户端核心插件
|
1
oauth/lang/zh_CN/providers.yml
Normal file
1
oauth/lang/zh_CN/providers.yml
Normal file
@ -0,0 +1 @@
|
||||
title: 其它登录方式
|
18
oauth/package.json
Normal file
18
oauth/package.json
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "oauth",
|
||||
"title": "Blessing\\OAuthCore::general.title",
|
||||
"version": "1.0.0",
|
||||
"description": "Blessing\\OAuthCore::general.description",
|
||||
"author": "GPlane",
|
||||
"url": "https://gplane.win/",
|
||||
"namespace": "Blessing\\OAuthCore",
|
||||
"require": {
|
||||
"blessing-skin-server": "^5.0.0"
|
||||
},
|
||||
"enchants": {
|
||||
"icon": {
|
||||
"bg": "primary",
|
||||
"fa": "box"
|
||||
}
|
||||
}
|
||||
}
|
58
oauth/src/AuthController.php
Normal file
58
oauth/src/AuthController.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Blessing\OAuthCore;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use Blessing\Filter;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Laravel\Socialite\Facades\Socialite;
|
||||
use Vectorface\Whip\Whip;
|
||||
|
||||
class AuthController extends Controller
|
||||
{
|
||||
public function login($driver)
|
||||
{
|
||||
return Socialite::driver($driver)->redirect();
|
||||
}
|
||||
|
||||
public function callback(Dispatcher $dispatcher, Filter $filter, $driver)
|
||||
{
|
||||
$remoteUser = Socialite::driver($driver)->user();
|
||||
|
||||
$email = $remoteUser->email;
|
||||
if (empty($email)) {
|
||||
abort(500, 'Unsupported OAuth Server which does not provide email.');
|
||||
}
|
||||
|
||||
$user = User::where('email', $email)->first();
|
||||
if (!$user) {
|
||||
$whip = new Whip();
|
||||
$ip = $whip->getValidIpAddress();
|
||||
$ip = $filter->apply('client_ip', $ip);
|
||||
|
||||
$user = new User();
|
||||
$user->email = $email;
|
||||
$user->nickname = $remoteUser->nickname ?? $remoteUser->name ?? $email;
|
||||
$user->score = option('user_initial_score');
|
||||
$user->avatar = 0;
|
||||
$user->password = '';
|
||||
$user->ip = $ip;
|
||||
$user->permission = User::NORMAL;
|
||||
$user->register_at = Carbon::now();
|
||||
$user->last_sign_at = Carbon::now()->subDay();
|
||||
$user->verified = true;
|
||||
|
||||
$user->save();
|
||||
$dispatcher->dispatch('auth.registration.completed', [$user]);
|
||||
}
|
||||
|
||||
$dispatcher->dispatch('auth.login.ready', [$user]);
|
||||
Auth::login($user);
|
||||
$dispatcher->dispatch('auth.login.succeeded', [$user]);
|
||||
|
||||
return redirect('/user');
|
||||
}
|
||||
}
|
11
oauth/views/providers.twig
Normal file
11
oauth/views/providers.twig
Normal file
@ -0,0 +1,11 @@
|
||||
{% if providers|length > 0 %}
|
||||
<div class="my-3 text-center">
|
||||
<div class="mb-1">{{ trans('Blessing\\OAuthCore::providers.title') }}</div>
|
||||
{% for name, provider in providers %}
|
||||
<a href="{{ url("/auth/login/#{name}") }}" class="btn btn-block bg-light border-secondary">
|
||||
<i class="fab fa-{{ provider.icon }}"></i>
|
||||
{{ provider.displayName }}
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
Loading…
Reference in New Issue
Block a user