Laravel Socialite? ???? ???????? OAuth ? OAuth2 ?? ??? ???? ? ??? ?? ?? Laravel ??????. Facebook, Twitter, Google, LinkedIn, GitHub, GitLab ? Bitbucket? ????? ?????. Socialite? ???? ???? ?? ?? ????? ??? ? ????.
? ???? ??? ??? ????.
- ?????? ?? ?? ?? ?? ?? ?????.
- Socialite? ?? Google ??? ??? Laravel ????? ???? ??? ?????.
- ????? ??? ??? ?????.
TLDR: ? GitHub?? ??? ????? ? ? ????. ??? ??? ?? ??? ? ? ?????.
Laravel Socialite? ??? ?? ??? ?? ?????
Socialite? ?? API? ?? ? ?? ?? ???? ??? ?? ??????.
- Socialite::driver($authProvider)->redirect()? ???? ??? ?? ????? ?????? URL ????? ?? ??? ??? ????? ?????.
- Socialite::driver($authProvider)->user()? ?? ?????? ?? ??? ??? ???? ???? ??????? ??? ? ??? ???.
?? ?? ? ??? ????? ?? ?? ?? ??? ????. ?? ?? ??? Socialite ???? ???? ? ????.
Socialite? ??? ???? ???? ??? ??? ??? ????? ????.
- ? ?? ?? ???? ???? ? ??? ?????? ????? ?? ????.
- ? ?? ???? ???? ?? ???? ?????.
- ? OAuth ??? ??? ? ???? ?????.
- ? OAuth ??? ?? ????.
?? ??: Google Cloud ???? ???
???? Google? ?? ??? ? ?? ??? Socialite ????? ???????. ??? ???? ?? ?? ???? ???.
?? ? Google Cloud ????? ?? ?? ????? ?? OAuth ?? ??? ?????. ??? ??? ??? ??? ? ?? ??? ??????.
- .../auth/userinfo.email
- .../auth/userinfo.profile
?? ??? ??? ? Google Cloud ?? ?? ???? ???? OAuth 2.0 ????? ID? ?????. ????? ID? ????? ????? ?????. ??? ?????? ??? ????.
Socialite? ???? ?? Laravel ???? ??
? Laravel ???? ???:
laravel new socialite-tests
?? ?????? ?? ??? ?????.
┌ Would you like to install a starter kit? ────────────────────┐ │ No starter kit │ └──────────────────────────────────────────────────────────────┘ ┌ Which testing framework do you prefer? ──────────────────────┐ │ Pest │ └──────────────────────────────────────────────────────────────┘ ┌ Which database will your application use? ───────────────────┐ │ SQLite │ └──────────────────────────────────────────────────────────────┘ ┌ Would you like to run the default database migrations? ──────┐ │ Yes │ └──────────────────────────────────────────────────────────────┘
???? ????? ???? Socialite? ?????.
laravel new socialite-tests
? ??????? ?????.
┌ Would you like to install a starter kit? ────────────────────┐ │ No starter kit │ └──────────────────────────────────────────────────────────────┘ ┌ Which testing framework do you prefer? ──────────────────────┐ │ Pest │ └──────────────────────────────────────────────────────────────┘ ┌ Which database will your application use? ───────────────────┐ │ SQLite │ └──────────────────────────────────────────────────────────────┘ ┌ Would you like to run the default database migrations? ──────┐ │ Yes │ └──────────────────────────────────────────────────────────────┘
database/migrations? ?? ??? ?????? ??? ?? ??? ?????.
cd socialite-tests composer require laravel/socialite
? ???????? ???? ????? ???? Socialite?? ??? ??? ?????. ????? ???? ?? ??? ??? ??? ???? ?? ?????. Google?? ? ?? ???? ????? ???? ?? ???? ??? ? ?? ??? ???? ??? ?? ????.
???? Google? ???? ???? ?? ????? ???? ???? ????? null ???? ?????. ??? ?? ??? ???? ??? ???? ?? ???? ????? ?? ???? ??? ? ????? ?? ??? null? ??? ??? ???? ???.
??????? ?????.
php artisan make:migration add_socialite_fields_to_users
config/services.php?? ??? ?? ?? ?? ?? ??? ?????. ?? ???? ??? Socialite ??? ??? ?? ??? ?? ? ????.
<?php // database/migrations/2024_12_31_075619_add_socialite_fields_to_users.php use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; return new class extends Migration { /** * Run the migrations. */ public function up(): void { Schema::table('users', function (Blueprint $table) { $table->string('google_id')->default(''); $table->string('google_token')->default(''); $table->string('google_refresh_token')->default(''); // If your app allows both password and social logins, you // MUST validate that the password is not blank during login. // If you do not, an attacker could gain access to an account // that uses social login by only knowing the email. $table->string('password')->nullable()->change(); }); } /** * Reverse the migrations. */ public function down(): void { Schema::table('users', function (Blueprint $table) { $table->dropColumn('google_id'); $table->dropColumn('google_token'); $table->dropColumn('google_refresh_token'); $table->string('password')->nullable(false)->change(); }); } };
'?? ??' ???? ??? Google ?? ?? ??? ???? .env? ??? ?????.
php artisan migrate
routes/web.php? ??? ?? ??? ????.
// config/services.php 'google' => [ 'client_id' => env('GOOGLE_CLIENT_ID'), 'client_secret' => env('GOOGLE_CLIENT_SECRET'), 'redirect' => '/auth/google/callback', ],
? ??? ? ??? ?? ??? ?????.
- ??? ??? ???? ?? ???? ?? Google? ???????.
- Google? ??? ?????. ? ??? ??? ? ???? ????? ????? ? ???? ????? ???????.
- ??? ???? ???????.
????? resources/views/welcome.php? ??? ?? ????? ????.
# .env GOOGLE_CLIENT_ID="your-google-client-id" GOOGLE_CLIENT_SECRET="your-google-client-secret"
? ??? ???? ?? ??? ???? ?? ???? ???? ? ????.
<?php // routes/web.php use App\Models\User; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Route; use Laravel\Socialite\Facades\Socialite; use Laravel\Socialite\Two\InvalidStateException; use Laravel\Socialite\Two\User as OAuth2User; Route::get('/', function () { return view('welcome'); }); Route::get('/auth/google/redirect', function () { return Socialite::driver('google')->redirect(); }); Route::get('/auth/google/callback', function () { try { /** @var OAuth2User $google_user */ $google_user = Socialite::driver('google')->user(); } catch (InvalidStateException $exception) { abort(400, $exception->getMessage()); } $user = User::updateOrCreate([ 'email' => $google_user->email, ], [ 'google_id' => $google_user->id, 'name' => $google_user->name, 'google_token' => $google_user->token, 'google_refresh_token' => $google_user->refreshToken, ]); Auth::login($user); return redirect('/'); }); Route::get('/auth/logout', function () { Auth::logout(); return redirect('/'); });
Google? ??? ??? ???? OAuth2 ??? ?? Google?? ?? ??? ???? ?? ??? ? ? ?? ????? ???????.
???? ??? ?? ?????
?? ???? ????? ???? ??? ? ??? ???? ??? ???? ?? ???? ???? ????.
?? ???? ??? ??? ??? ??? ? ????.
<!-- resources/views/welcome.php --> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Laravel Socialite Testing Example</title> </head> <body> <h1>Laravel Socialite Testing Example</h1> @if (auth()->check()) <p>User is authenticated.</p> <p>Name: {{ auth()->user()->name }}</p> <p>Email: {{ auth()->user()->email }}</p> <p><a href="/auth/logout">Logout</a></p> @else <p>User is not authenticated.</p> <p> <a href="/auth/google/redirect">Login with Google</a> </p> @endif </body> </html>
?? ??? ???/Feature/AuthRoutesTest.php? ??? ???? ????.
php artisan serve
??? ?? ??
???? ??? ???? ? Socialite? ??? URL? ?????? ??? URL ????? ????? ??????.
?? ??? ???? ? Socialite? ?????. ??? ?? ?? ???? ??? ????. ???? ????? Socialite? ?? OAuth2 ???? ??? ? ??? ???? ??? ??? ????. ??? Socialite? ??? ??? ???? ?? ??? ?? ?? ??? ???? ??? ??? ????. ??? ??? ??? ?????? ????? ?? ???? ?? ?????.
Fluent API? Mockery? ?? ????? ?????. ?? ???? ???? ??? ???? ???.
?? ?????? ???? Socialite ???? ??? ????.
laravel new socialite-tests
Mockery? ?? ?? ???? ??? ??? ????.
┌ Would you like to install a starter kit? ────────────────────┐ │ No starter kit │ └──────────────────────────────────────────────────────────────┘ ┌ Which testing framework do you prefer? ──────────────────────┐ │ Pest │ └──────────────────────────────────────────────────────────────┘ ┌ Which database will your application use? ───────────────────┐ │ SQLite │ └──────────────────────────────────────────────────────────────┘ ┌ Would you like to run the default database migrations? ──────┐ │ Yes │ └──────────────────────────────────────────────────────────────┘
????? OAuth ?? ??? ?? URL? ?? ???? 400 ?? ??? ????? ???? ???? ????. try/catch ?? ?? ?? ??????? Socialite::driver('google')->user()? ?? ??? ??????. Socialite ??? try/catch ???? ???? ??? ??? ????? ?? URL? ??? ?? ?????? HTTP 500 ?? ??? ?? ??? ??????. ??? 500?? ?? ??? ?? ????? ??? ?? ??? ???? ??? ?? ? ????.
???
??? ???? ???? ??? ? ?? ?? ?? ? ????. ???? ???? ??? ? ?? ?? ????? ??? ???? ?? ? ??? ??? ??? ????? ???? ????. ???? ? ??? ??? ??? ??? ? ?? ???? ?? ??? ? ??? ???? ????. ??? ?? Socialite? ????? ??? ??????? ??? ????? ?? ???? ???? ?? ??? ???? ??? ? ????.
?? Socialite? ?? ?? ??? ??? ?? ???? ?? ?? ?? ??? ???? ??, ????? ??, ???? ? ??? ??????. ???? ? ? ??? ???? ????.
- Stefan Zweifel? Laravel Socialite ?? ?? ?? ?? ??? ?? ??
- ServerSideUp ??: Socialite ?? ??, ??
- ?? ????: Laravel Socialite ??? ??
- ?? ??: ?? ???? ???? ???? ????? ???? ????
- Stack Exchange: ??? ?? ?? ? ???? ?? ??
? ??? ???? ??? ?????. ??, ?? ?? ??? ??, ???? ??? ?? ?? ?? ?? ?? ?? ?? ??? ?? ??? ???? ? ???? 2??? ??? ???? ????? ????.
? ??? Laravel?? Socialite ?? ?? ? ???? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

??? ??











TOSECURELYHANDLEAUSTENCENDACTIONANDACTERIZINGINPHP, FORCUCTSESTEPS : 1. ALWAYSHASHPASSWORTHPASSWORD_HASH () ? VERVERIFYUSINGPANSWORD_VERIFY (), usePREPAREDSTATEMENTSTOPREVENTSQLINGERGED, andSTOREUSERSESSEATAIN $ _SESSIONSAFTERLOGIN.2.impleplempletrole ?? ACCESSC

PHP?? ?? ???? ???? ????? ??? ?? ??? ???? ?? ??? ??? ??? ???? ????. 1. finfo_file ()? ???? ?? ?? ??? ???? ???/jpeg? ?? ?? ?? ? ?????. 2. uniqid ()? ???? ??? ?? ??? ???? ? Web ?? ????? ??????. 3. php.ini ? html ??? ?? ?? ??? ???? ???? ??? 0755? ?????. 4. Clamav? ???? ???? ???? ??? ??????. ??? ??? ?? ???? ????? ???? ?? ??? ????? ???? ??? ? ??? ?????.

PHP?? ==? ==? ?? ???? ?? ??? ??????. == ?? ??? ?? ?? ?????. ?? ??, 5 == "5"? true? ????, ?? ??? ???? ?? ?? ??? ????? ????? (? : 5 === "5"? false? ?????. ?? ?????? ===? ? ???? ?? ?????? == ?? ??? ??? ???? ?????.

PHP?? ?? ??? ??? ???? ??? ??? ????. 1. ?? ??? ?? ? ?? ??? ??? ???? ???? ??? ? ????. ??? ??? ???? ????? ????? ???? ????. 2. ?? ?? ?? - ??, ??? ???? ?? ??? ?????. 3. ?? ???? ??? ??? ???? ??? ??? ?????. 4. Division? / ??? ???? 0?? ??? ?? ????? ??? ?? ??? ?? ? ? ????. 5. ???? ??? ???? ?? ?? ? ?? ??? ???? ? ??? ? ???, ??? ?? ? ? ??? ??? ???? ?????. ? ???? ???? ???? ??? ??? ??? ???? ?? ??? ? ??????? ????.

?, PHP? ?? ?? ?? ?????? ?? MongoDB ? Redis? ?? NOSQL ??????? ?? ??? ? ????. ?? MongoDBPHP ???? (PECL ?? Composer? ?? ??)? ???? ????? ????? ??? ?????? ? ???? ????? ??, ??, ?? ? ?? ??? ?????. ??, Predis ????? ?? Phpredis ??? ???? Redis? ???? ?? ? ?? ? ??? ???? ??? ????? Phpredis? ???? ?? Predis? ?? ??? ?????. ? ? ?? ??? ???? ? ????? ????.

tostaycurrentwithphpdevelopments ? bestpractices, followkeynewssources lifephp.netandphpweekly, adgytwithcommunitiesonforumsandconferences, readlingupdated andgrad indewfeatures, andreadorcontributetoopensourceproceprosts.first

phpbecamepupularforwebdevelopmentduetoiteofleneflening, whithhtml, wididepreadhostingsupport, andalargeecosystemincludingframeworkslikelaravelandcmsplatformsformslikewordpress.itexcelsinhandlingformsubmissions, managingussess, interptisussivers, ?? ???

TOSETTHERIGHTTIMEZONEINPHP, usedate_default_timezone_set () functionattStartOfyourscriptwitHavalidInlifiersuchas'America/new_york'.1.edate_default_timezone_set () beforeanydate/timeFunctions.2
