mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-05 15:38:15 +08:00
fix oauth login
This commit is contained in:
@@ -89,10 +89,21 @@ class OauthController extends Controller
|
|||||||
$response = Http::withToken($tokenInfo['access_token'])->get($provider->user_info_endpoint_url);
|
$response = Http::withToken($tokenInfo['access_token'])->get($provider->user_info_endpoint_url);
|
||||||
$userInfo = $response->json();
|
$userInfo = $response->json();
|
||||||
do_log("userInfo: " . $response->body());
|
do_log("userInfo: " . $response->body());
|
||||||
|
$homeUrl = getSchemeAndHttpHost() . "/index.php";
|
||||||
$providerUserId = data_get($userInfo, $provider->id_claim);
|
$providerUserId = data_get($userInfo, $provider->id_claim);
|
||||||
if (empty($providerUserId)) {
|
if (empty($providerUserId)) {
|
||||||
throw new NexusException(nexus_trans('oauth.get_provider_user_id_error', ['id_claim' => $provider->id_claim]));
|
throw new NexusException(nexus_trans('oauth.get_provider_user_id_error', ['id_claim' => $provider->id_claim]));
|
||||||
}
|
}
|
||||||
|
$socialAccount = SocialAccount::query()
|
||||||
|
->where('provider_id', $provider->id)
|
||||||
|
->where('provider_user_id', $providerUserId)
|
||||||
|
->first();
|
||||||
|
if ($socialAccount) {
|
||||||
|
//already bind, login directly
|
||||||
|
$authUser = $socialAccount->user;
|
||||||
|
logincookie($authUser->id, $authUser->auth_key);
|
||||||
|
return redirect($homeUrl);
|
||||||
|
}
|
||||||
$providerEmail = data_get($userInfo, $provider->email_claim);
|
$providerEmail = data_get($userInfo, $provider->email_claim);
|
||||||
if (empty($providerEmail)) {
|
if (empty($providerEmail)) {
|
||||||
throw new NexusException(nexus_trans('oauth.get_provider_email_error', ['email_claim' => $provider->email_claim]));
|
throw new NexusException(nexus_trans('oauth.get_provider_email_error', ['email_claim' => $provider->email_claim]));
|
||||||
@@ -104,17 +115,7 @@ class OauthController extends Controller
|
|||||||
}
|
}
|
||||||
$providerUsername = data_get($userInfo, $provider->username_claim);
|
$providerUsername = data_get($userInfo, $provider->username_claim);
|
||||||
$providerLevel = data_get($userInfo, $provider->level_claim);
|
$providerLevel = data_get($userInfo, $provider->level_claim);
|
||||||
$homeUrl = getSchemeAndHttpHost() . "/index.php";
|
|
||||||
$socialAccount = SocialAccount::query()
|
|
||||||
->where('provider_id', $provider->id)
|
|
||||||
->where('provider_user_id', $providerUserId)
|
|
||||||
->first();
|
|
||||||
if ($socialAccount) {
|
|
||||||
//already bind, login directly
|
|
||||||
$authUser = $socialAccount->user;
|
|
||||||
logincookie($authUser->id, $authUser->auth_key);
|
|
||||||
return redirect($homeUrl);
|
|
||||||
}
|
|
||||||
$minLevel = $provider->level_limit;
|
$minLevel = $provider->level_limit;
|
||||||
if ($minLevel) {
|
if ($minLevel) {
|
||||||
if (!$providerLevel) {
|
if (!$providerLevel) {
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ class NexusFormatter
|
|||||||
if (nexus()) {
|
if (nexus()) {
|
||||||
$id = nexus()->getRequestId();
|
$id = nexus()->getRequestId();
|
||||||
}
|
}
|
||||||
$id .= " -> " . getLogFile();
|
|
||||||
$format = "[%datetime%] [" . $id . "] %channel%.%level_name%: %message% %context% %extra%\n";
|
$format = "[%datetime%] [" . $id . "] %channel%.%level_name%: %message% %context% %extra%\n";
|
||||||
return tap(new LineFormatter($format, 'Y-m-d H:i:s', true, true), function ($formatter) {
|
return tap(new LineFormatter($format, 'Y-m-d H:i:s', true, true), function ($formatter) {
|
||||||
$formatter->includeStacktraces();
|
$formatter->includeStacktraces();
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ return [
|
|||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'default' => env('LOG_CHANNEL', 'daily'),
|
'default' => env('LOG_CHANNEL', 'single'),
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
@@ -37,7 +37,7 @@ return [
|
|||||||
'channels' => [
|
'channels' => [
|
||||||
'stack' => [
|
'stack' => [
|
||||||
'driver' => 'stack',
|
'driver' => 'stack',
|
||||||
'channels' => ['daily'],
|
'channels' => ['single'],
|
||||||
'ignore_exceptions' => false,
|
'ignore_exceptions' => false,
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user