feature/PassportLogin #2

Open
witel wants to merge 3 commits from feature/PassportLogin into develop
3 changed files with 26 additions and 4 deletions
Showing only changes of commit 7a6decc506 - Show all commits

View File

@@ -67,3 +67,6 @@ VITE_APP_NAME="${APP_NAME}"
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
GOOGLE_REDIRECT_URI=
PASSWORD_CLINT_ID=
PASSWORD_CLINT_SECRET=

View File

@@ -4,9 +4,11 @@ namespace App\User\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Http\Client\ConnectionException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Str;
use Laravel\Socialite\Facades\Socialite;
@@ -18,11 +20,14 @@ class AuthController extends Controller
}
/**
* @throws ConnectionException
*/
public function registerGoogle($driver):JsonResponse
{
$socialUser = Socialite::driver($driver)->user();
$user = User::updateOrCreate(
$user = User::query()->updateOrCreate(
['email' => $socialUser->getEmail()],
[
'name' => $socialUser->getName(),
@@ -30,11 +35,17 @@ class AuthController extends Controller
]
);
$token = $user->createToken('auth_token')->accessToken;
$response = Http::asForm()->post(config('app.url') . '/oauth/token', [
'grant_type' => 'password',
'client_id' => config('passport.password_client_id'),
'client_secret' => config('passport.password_client_secret'),
'username' => $user->email,
'password' => 'dummy_password_because_socialite_authenticated',
'scope' => '*',
]);
return response()->json([
'user' => $user,
'access_token' => $token,
'token_type' => 'Bearer',
'token' => $response->json(),
]);
}}

View File

@@ -0,0 +1,8 @@
<?php
return [
'Passport' => [
'id' => env('PASSWORD_CLINT_ID'),
'secret' => env('PASSWORD_CLINT_SECRET'),
],
];