移除 OAuth
This commit is contained in:
parent
a01f9f08fc
commit
156e3fcb28
@ -55,11 +55,6 @@ VITE_PUSHER_PORT="${PUSHER_PORT}"
|
|||||||
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
|
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
|
||||||
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
|
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
|
||||||
|
|
||||||
OAUTH_CLIENT_ID=
|
|
||||||
OAUTH_CLIENT_SECRET=
|
|
||||||
OAUTH_REDIRECT=http://www.lae.test/auth/callback
|
|
||||||
OAUTH_DOMAIN=
|
|
||||||
|
|
||||||
ALIPAY_APP_ID=
|
ALIPAY_APP_ID=
|
||||||
ALIPAY_APP_SECERT_CERT_PATH=
|
ALIPAY_APP_SECERT_CERT_PATH=
|
||||||
ALIPAY_APP_PUBLIC_CERT_PATH=
|
ALIPAY_APP_PUBLIC_CERT_PATH=
|
||||||
|
@ -61,89 +61,6 @@ public function confirm_redirect(Request $request): View
|
|||||||
return view('confirm_redirect', compact('callback'));
|
return view('confirm_redirect', compact('callback'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function redirect(Request $request): RedirectResponse
|
|
||||||
{
|
|
||||||
$request->session()->put('state', $state = Str::random(40));
|
|
||||||
|
|
||||||
$query = http_build_query([
|
|
||||||
'client_id' => config('oauth.client_id'),
|
|
||||||
'redirect_uri' => config('oauth.callback_uri'),
|
|
||||||
'response_type' => 'code',
|
|
||||||
'scope' => '',
|
|
||||||
'state' => $state,
|
|
||||||
'meta' => 'test_meta',
|
|
||||||
]);
|
|
||||||
|
|
||||||
return redirect()->to(config('oauth.oauth_auth_url').'?'.$query);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function callback(Request $request): RedirectResponse
|
|
||||||
{
|
|
||||||
$state = $request->session()->pull('state');
|
|
||||||
|
|
||||||
if (! strlen($state) > 0 && $state === $request->input('state')) {
|
|
||||||
return redirect(route('login'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$http = new Client();
|
|
||||||
|
|
||||||
try {
|
|
||||||
$authorize = $http->post(config('oauth.oauth_token_url'), [
|
|
||||||
'form_params' => [
|
|
||||||
'grant_type' => 'authorization_code',
|
|
||||||
'client_id' => config('oauth.client_id'),
|
|
||||||
'client_secret' => config('oauth.client_secret'),
|
|
||||||
'redirect_uri' => config('oauth.callback_uri'),
|
|
||||||
'code' => $request->input('code'),
|
|
||||||
],
|
|
||||||
])->getBody();
|
|
||||||
} catch (ClientException|GuzzleException) {
|
|
||||||
return redirect(route('login'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$authorize = json_decode($authorize);
|
|
||||||
|
|
||||||
try {
|
|
||||||
$oauth_user = $http->get(config('oauth.oauth_user_url'), [
|
|
||||||
'headers' => [
|
|
||||||
'Accept' => 'application/json',
|
|
||||||
'Authorization' => 'Bearer '.$authorize->access_token,
|
|
||||||
],
|
|
||||||
])->getBody();
|
|
||||||
} catch (GuzzleException) {
|
|
||||||
return redirect(route('login'));
|
|
||||||
}
|
|
||||||
$oauth_user = json_decode($oauth_user);
|
|
||||||
|
|
||||||
$user_sql = (new User)->where('email', $oauth_user->email);
|
|
||||||
$user = $user_sql->first();
|
|
||||||
|
|
||||||
if (is_null($user)) {
|
|
||||||
$name = $oauth_user->name;
|
|
||||||
$email = $oauth_user->email;
|
|
||||||
$email_verified_at = $oauth_user->email_verified_at ?? now();
|
|
||||||
|
|
||||||
$user = new User();
|
|
||||||
$user->name = $name;
|
|
||||||
$user->email = $email;
|
|
||||||
$user->password = null;
|
|
||||||
$user->email_verified_at = $email_verified_at;
|
|
||||||
$user->save();
|
|
||||||
|
|
||||||
$request->session()->put('auth.password_confirmed_at', time());
|
|
||||||
} else {
|
|
||||||
if ($user->name != $oauth_user->name) {
|
|
||||||
(new User)->where('email', $oauth_user->email)->update([
|
|
||||||
'name' => $oauth_user->name,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Auth::loginUsingId($user->id, true);
|
|
||||||
|
|
||||||
return redirect()->route('index', ['callback' => session('callback')]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function newToken(Request $request): RedirectResponse
|
public function newToken(Request $request): RedirectResponse
|
||||||
{
|
{
|
||||||
$request->validate([
|
$request->validate([
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
return [
|
|
||||||
'callback_uri' => env('OAUTH_REDIRECT'),
|
|
||||||
'client_id' => env('OAUTH_CLIENT_ID'),
|
|
||||||
'client_secret' => env('OAUTH_CLIENT_SECRET'),
|
|
||||||
'oauth_auth_url' => env('OAUTH_DOMAIN').'/oauth/authorize',
|
|
||||||
'oauth_token_url' => env('OAUTH_DOMAIN').'/oauth/token',
|
|
||||||
'oauth_user_url' => env('OAUTH_DOMAIN').'/api/user',
|
|
||||||
];
|
|
@ -15,9 +15,6 @@
|
|||||||
Route::get('/', [AuthController::class, 'index'])->name('index')->middleware('banned');
|
Route::get('/', [AuthController::class, 'index'])->name('index')->middleware('banned');
|
||||||
|
|
||||||
Route::prefix('auth')->group(function () {
|
Route::prefix('auth')->group(function () {
|
||||||
// Route::get('redirect', [AuthController::class, 'redirect'])->name('login');
|
|
||||||
// Route::get('callback', [AuthController::class, 'callback'])->name('callback');
|
|
||||||
|
|
||||||
Route::get('login', [LoginController::class, 'showLoginForm'])->name('login');
|
Route::get('login', [LoginController::class, 'showLoginForm'])->name('login');
|
||||||
Route::post('login', [LoginController::class, 'login']);
|
Route::post('login', [LoginController::class, 'login']);
|
||||||
Route::post('logout', [LoginController::class, 'logout'])->name('logout');
|
Route::post('logout', [LoginController::class, 'logout'])->name('logout');
|
||||||
|
Loading…
Reference in New Issue
Block a user