{"id":380172,"date":"2024-06-27T15:01:44","date_gmt":"2024-06-27T15:01:44","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=380172"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=380172","title":{"rendered":"<span>\u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f \u0447\u0435\u0440\u0435\u0437 Yandex, \u0412\u041a, Telegram \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Laravel Socialite<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h3>\u0412\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0412 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 \u0435\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0430\u0442\u0435\u0439 \u0438 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432 \u043f\u043e \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438 OAuth \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u043e\u0432, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a Google, Facebook \u0438 Twitter, \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u044b \u043d\u0430 Laravel. \u041d\u043e \u043a\u0430\u043a \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 Yandex, \u0412\u041a \u0438 \u0442.\u043f. \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0432 \u0440\u0443\u043d\u0435\u0442\u0435 \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435\u0442.<\/p>\n<p>\u0411\u0443\u0434\u0443 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u042f\u043d\u0434\u0435\u043a\u0441\u0430. \u0427\u0435\u0440\u0435\u0437 \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u044b \u0434\u0435\u043b\u0430\u0439\u0442\u0435 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e.<\/p>\n<h3>\u0428\u0430\u0433 1. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/h3>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432 <a href=\"https:\/\/oauth.yandex.ru\/client\/new\/id\/\" rel=\"noopener noreferrer nofollow\">Yandex OAuth<\/a><\/p>\n<figure class=\"bordered full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f3a\/33f\/ff9\/f3a33fff962a86fbee4e3666eac19bcc.png\" alt=\"\u0412\u0432\u043e\u0434\u0438\u043c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0438 \u0442.\u043a. \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c Laravel - \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0412\u0435\u0431-\u0441\u0435\u0440\u0432\u0438\u0441\u044b\" title=\"\u0412\u0432\u043e\u0434\u0438\u043c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0438 \u0442.\u043a. \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c Laravel - \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0412\u0435\u0431-\u0441\u0435\u0440\u0432\u0438\u0441\u044b\" width=\"676\" height=\"663\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f3a\/33f\/ff9\/f3a33fff962a86fbee4e3666eac19bcc.png\"\/><\/p>\n<div><figcaption>\u0412\u0432\u043e\u0434\u0438\u043c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0438 \u0442.\u043a. \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c Laravel &#8212; \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0412\u0435\u0431-\u0441\u0435\u0440\u0432\u0438\u0441\u044b<\/figcaption><\/div>\n<\/figure>\n<figure class=\"bordered full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/298\/9d6\/af1\/2989d6af1b8b19018408079b905ac02f.png\" alt=\"\u0412\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443, \u043a\u0443\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u043e\u0441\u043b\u0435 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u0443\u044e)\" title=\"\u0412\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443, \u043a\u0443\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u043e\u0441\u043b\u0435 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u0443\u044e)\" width=\"704\" height=\"489\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/298\/9d6\/af1\/2989d6af1b8b19018408079b905ac02f.png\"\/><\/p>\n<div><figcaption>\u0412\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443, \u043a\u0443\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u043e\u0441\u043b\u0435 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u0443\u044e)<\/figcaption><\/div>\n<\/figure>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u044d\u0442\u0438 3 \u043f\u043e\u043b\u044f, \u043e\u043d\u0438 \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f \u0447\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/426\/c70\/b33\/426c70b33c8585085d495faefd51ec68.png\" width=\"789\" height=\"302\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/426\/c70\/b33\/426c70b33c8585085d495faefd51ec68.png\"\/><\/figure>\n<h3>\u0428\u0430\u0433 2. \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 Socialite<\/h3>\n<p>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c  Laravel Socialite  \u0432 \u043d\u0430\u0448 \u043f\u0440\u043e\u0435\u043a\u0442 \u0447\u0435\u0440\u0435\u0437 composer<\/p>\n<pre><code>composer require laravel\/socialite<\/code><\/pre>\n<p>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c  SocialiteProviders   <\/p>\n<p>SocialiteProviders &#8212; \u044d\u0442\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u0434\u043b\u044f Laravel Socialite, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u043c\u043d\u043e\u0433\u0438\u0445 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 OAuth-\u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u043e\u0432, \u0432\u043a\u043b\u044e\u0447\u0430\u044f Yandex, \u0412\u041a, Telegram \u0438 \u0434\u0440\u0443\u0433\u0438\u0435. \u041f\u043e\u043b\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u043e\u0432 \u043d\u0430 \u0438\u0445 <a href=\"https:\/\/socialiteproviders.com\/about\/\" rel=\"noopener noreferrer nofollow\">\u0441\u0430\u0439\u0442\u0435<\/a>.<\/p>\n<pre><code>composer require socialiteproviders\/yandex<\/code><\/pre>\n<h3>\u0428\u0430\u0433 3. \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/h3>\n<p>\u0412 \u0444\u0430\u0439\u043b\u0435 <code>config\/services.php<\/code> \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0434\u043b\u044f Yandex:  <\/p>\n<pre><code>'yandex' => [     'client_id' => env('YANDEX_CLIENT_ID'),     'client_secret' => env('YANDEX_CLIENT_SECRET'),     'redirect' => env('YANDEX_REDIRECT_URI'), ],<\/code><\/pre>\n<p> \u0412\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0432 <code>.env<\/code> \u0444\u0430\u0439\u043b \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u043c \u0434\u0430\u043b \u042f\u043d\u0434\u0435\u043a\u0441:  <\/p>\n<pre><code>YANDEX_CLIENT_ID=*ClientID* YANDEX_CLIENT_SECRET=*Client secret* YANDEX_REDIRECT_URI=*Redirect URI \u0434\u043b\u044f \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432*<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u044b \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u0430 Yandex \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430:<\/p>\n<pre><code>Route::get('login\/yandex', [AuthenticatedSessionController::class, 'yandex'])->name('yandex'); Route::get('login\/yandex\/redirect', [AuthenticatedSessionController::class, 'yandexRedirect'])->name('yandexRedirect');<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440:<\/p>\n<pre><code>    use Laravel\\Socialite\\Facades\\Socialite;     use Str;        public function yandex() \/\/ \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u044e\u0437\u0435\u0440\u0430 \u043d\u0430 \u044f\u043d\u0434\u0435\u043a\u0441 Auth     {         return Socialite::driver('yandex')->redirect();     }      public function yandexRedirect() \/\/ \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u043d\u0438\u043c\u0438     {         $user = Socialite::driver('yandex')->user();          $user = User::firstOrCreate([ \/\/ \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c firstOrCreate \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0435\u0441\u0442\u044c \u043b\u0438 \u0442\u0430\u043a\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0432 \u043d\u0430\u0448\u0435\u0439 \u0411\u0414             'email' => $user->email         ], [             'name' => $user->user['display_name'], \/\/ display_name - \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u0430\u0430\u044f \u0445\u0440\u0430\u043d\u044f\u0449\u0430\u044f \u043f\u043e\u043b\u043d\u043e\u0435 \u0424\u0418\u041e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f                                                   \/\/ \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0432 $dd('$user')             'password' => Hash::make(Str::random(24)),         ]);          Auth::login($user, true);          redirect()->route('main');     }<\/code><\/pre>\n<p>\u0421\u0442\u0430\u0432\u0438\u0432 \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443 &#171;\u0432\u043e\u0439\u0442\u0438 \u0447\u0435\u0440\u0435\u0437 \u044f\u043d\u0434\u0435\u043a\u0441&#187; \u043d\u0430\u0448 \u043f\u0435\u0440\u0432\u044b\u0439 \u043c\u0430\u0440\u0448\u0440\u0443\u0442 \u0438 \u0433\u043e\u0442\u043e\u0432\u043e. \u041f\u043e \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u0441\u0445\u0435\u043c\u0435 \u0434\u0435\u043b\u0430\u0435\u0442\u0435 telegram, vk \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0435 \u0432 socialiteproviders. <\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/825134\/\"> https:\/\/habr.com\/ru\/articles\/825134\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h3>\u0412\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/h3>\n<p>\u0412 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0435 \u0435\u0441\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0430\u0442\u0435\u0439 \u0438 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432 \u043f\u043e \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u0438 OAuth \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u043e\u0432, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a Google, Facebook \u0438 Twitter, \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u044b \u043d\u0430 Laravel. \u041d\u043e \u043a\u0430\u043a \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 Yandex, \u0412\u041a \u0438 \u0442.\u043f. \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0432 \u0440\u0443\u043d\u0435\u0442\u0435 \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435\u0442.<\/p>\n<p>\u0411\u0443\u0434\u0443 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u042f\u043d\u0434\u0435\u043a\u0441\u0430. \u0427\u0435\u0440\u0435\u0437 \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u044b \u0434\u0435\u043b\u0430\u0439\u0442\u0435 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e.<\/p>\n<h3>\u0428\u0430\u0433 1. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/h3>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432 <a href=\"https:\/\/oauth.yandex.ru\/client\/new\/id\/\" rel=\"noopener noreferrer nofollow\">Yandex OAuth<\/a><\/p>\n<figure class=\"bordered full-width\">\n<div><figcaption>\u0412\u0432\u043e\u0434\u0438\u043c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0438 \u0442.\u043a. \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c Laravel &#8212; \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0412\u0435\u0431-\u0441\u0435\u0440\u0432\u0438\u0441\u044b<\/figcaption><\/div>\n<\/figure>\n<figure class=\"bordered full-width\">\n<div><figcaption>\u0412\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443, \u043a\u0443\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u043e\u0441\u043b\u0435 \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u0443\u044e)<\/figcaption><\/div>\n<\/figure>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u044d\u0442\u0438 3 \u043f\u043e\u043b\u044f, \u043e\u043d\u0438 \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f \u0447\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435.<\/p>\n<figure class=\"full-width\"><\/figure>\n<h3>\u0428\u0430\u0433 2. \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 Socialite<\/h3>\n<p>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c  Laravel Socialite  \u0432 \u043d\u0430\u0448 \u043f\u0440\u043e\u0435\u043a\u0442 \u0447\u0435\u0440\u0435\u0437 composer<\/p>\n<pre><code>composer require laravel\/socialite<\/code><\/pre>\n<p>\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c  SocialiteProviders   <\/p>\n<p>SocialiteProviders &#8212; \u044d\u0442\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u0434\u043b\u044f Laravel Socialite, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u043c\u043d\u043e\u0433\u0438\u0445 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 OAuth-\u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u043e\u0432, \u0432\u043a\u043b\u044e\u0447\u0430\u044f Yandex, \u0412\u041a, Telegram \u0438 \u0434\u0440\u0443\u0433\u0438\u0435. \u041f\u043e\u043b\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u043e\u0432 \u043d\u0430 \u0438\u0445 <a href=\"https:\/\/socialiteproviders.com\/about\/\" rel=\"noopener noreferrer nofollow\">\u0441\u0430\u0439\u0442\u0435<\/a>.<\/p>\n<pre><code>composer require socialiteproviders\/yandex<\/code><\/pre>\n<h3>\u0428\u0430\u0433 3. \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/h3>\n<p>\u0412 \u0444\u0430\u0439\u043b\u0435 <code>config\/services.php<\/code> \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0434\u043b\u044f Yandex:  <\/p>\n<pre><code>'yandex' => [     'client_id' => env('YANDEX_CLIENT_ID'),     'client_secret' => env('YANDEX_CLIENT_SECRET'),     'redirect' => env('YANDEX_REDIRECT_URI'), ],<\/code><\/pre>\n<p> \u0412\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0432 <code>.env<\/code> \u0444\u0430\u0439\u043b \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u043c \u0434\u0430\u043b \u042f\u043d\u0434\u0435\u043a\u0441:  <\/p>\n<pre><code>YANDEX_CLIENT_ID=*ClientID* YANDEX_CLIENT_SECRET=*Client secret* YANDEX_REDIRECT_URI=*Redirect URI \u0434\u043b\u044f \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432*<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u044b \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u0430 Yandex \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430:<\/p>\n<pre><code>Route::get('login\/yandex', [AuthenticatedSessionController::class, 'yandex'])->name('yandex'); Route::get('login\/yandex\/redirect', [AuthenticatedSessionController::class, 'yandexRedirect'])->name('yandexRedirect');<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440:<\/p>\n<pre><code>    use Laravel\\Socialite\\Facades\\Socialite;     use Str;        public function yandex() \/\/ \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u044e\u0437\u0435\u0440\u0430 \u043d\u0430 \u044f\u043d\u0434\u0435\u043a\u0441 Auth     {         return Socialite::driver('yandex')->redirect();     }      public function yandexRedirect() \/\/ \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u043d\u0438\u043c\u0438     {         $user = Socialite::driver('yandex')->user();          $user = User::firstOrCreate([ \/\/ \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c firstOrCreate \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0435\u0441\u0442\u044c \u043b\u0438 \u0442\u0430\u043a\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0432 \u043d\u0430\u0448\u0435\u0439 \u0411\u0414             'email' => $user->email         ], [             'name' => $user->user['display_name'], \/\/ display_name - \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u0430\u0430\u044f \u0445\u0440\u0430\u043d\u044f\u0449\u0430\u044f \u043f\u043e\u043b\u043d\u043e\u0435 \u0424\u0418\u041e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f                                                   \/\/ \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0432 $dd('$user')             'password' => Hash::make(Str::random(24)),         ]);          Auth::login($user, true);          redirect()->route('main');     }<\/code><\/pre>\n<p>\u0421\u0442\u0430\u0432\u0438\u0432 \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443 &#171;\u0432\u043e\u0439\u0442\u0438 \u0447\u0435\u0440\u0435\u0437 \u044f\u043d\u0434\u0435\u043a\u0441&#187; \u043d\u0430\u0448 \u043f\u0435\u0440\u0432\u044b\u0439 \u043c\u0430\u0440\u0448\u0440\u0443\u0442 \u0438 \u0433\u043e\u0442\u043e\u0432\u043e. \u041f\u043e \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u0441\u0445\u0435\u043c\u0435 \u0434\u0435\u043b\u0430\u0435\u0442\u0435 telegram, vk \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0435 \u0432 socialiteproviders. <\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/825134\/\"> https:\/\/habr.com\/ru\/articles\/825134\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-380172","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/380172","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=380172"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/380172\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=380172"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=380172"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=380172"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}