change formate apassport for OAuth Client Grants
This commit is contained in:
@@ -67,3 +67,6 @@ VITE_APP_NAME="${APP_NAME}"
|
||||
GOOGLE_CLIENT_ID=
|
||||
GOOGLE_CLIENT_SECRET=
|
||||
GOOGLE_REDIRECT_URI=
|
||||
|
||||
PASSWORD_CLINT_ID=
|
||||
PASSWORD_CLINT_SECRET=
|
||||
|
||||
@@ -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(),
|
||||
]);
|
||||
}}
|
||||
|
||||
8
backend/config/passport.php
Normal file
8
backend/config/passport.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'Passport' => [
|
||||
'id' => env('PASSWORD_CLINT_ID'),
|
||||
'secret' => env('PASSWORD_CLINT_SECRET'),
|
||||
],
|
||||
];
|
||||
Reference in New Issue
Block a user