![]() Return $this->redirectToProvider($driver) Ībove is the complete code of SocialControler.php. Public function handleProviderCallback($driver) Return (new $this->providers)->redirect() Public function redirectToProvider($driver) * Redirect the user to provider authentication page The above command will generate a SocialController.php file to app/Http/Controllers/Auth directory. Php artisan make:controller Auth/SocialController Next step is to create the Auth\SocialController using the make:controller artisan command. Route::get('auth/', ['as' => 'socialAuth', 'uses' => ['as' => 'socialAuthCallback', 'uses' => your button links might look like this: Next step is to add a routes to routes/web.php that will redirect to the provider that we are going to support (e.g., Facebook, Twitter, GitHub, etc.) and a callback url that will handle the data that is being returned by the third party provider. * The attributes that should be casted to native types. Next, make sure to cast the settings column to array in your User model: This is usually useful when you don't want to delete your existing table in your database. Php artisan make:migration add_settings_to_users_table -table=users $table->json('settings')->nullable() php artisan migrate ![]() Second is to create a new migration file and run migrate artisan command: In this way we can associate those different accounts in one account in our system by checking their Facebook or Twitter id. ![]() We are using json type column here because a user might using the same email in their Facebook and Twitter for example. ![]() $table->json('settings')->nullable() php artisan migrate:refresh There are two ways to achieve this, first is to update our users table migration file directly and run migrate:refresh artisan command: Now that Laravel Socialite is set, next we have to add a column in the users table. env file for security purposes and access it using Laravel env() helper function.įACEBOOK_CLIENT_SECRET=your_facebook_app_secretīelow is some of the links on how to get those client ids and secrets, and add those callback urls. Pro tip: Always store your credentials in. 'redirect' => env('FACEBOOK_CLIENT_CALLBACK') 'client_secret' => env('FACEBOOK_CLIENT_SECRET'), 'client_id' => env('FACEBOOK_CLIENT_ID'), Next, you need to add your credentials for the OAuth services your application wish to utilize. These credentials should be placed in your config/services.php configuration file, and should use the key facebook, twitter, linkedin, google, github or bitbucket, depending on the providers your application requires: 'Socialite' => Laravel\Socialite\Facades\Socialite::class, In the same file config/app.php, add the Socialite facade to the aliases array. Laravel\Socialite\SocialiteServiceProvider::class, Let's get started!įirst, we need to install the Laravel Socialite package:Īfter installing the Laravel Socialite package, add the Laravel\Socialite\SocialiteServiceProvider in your config/app.php configuration file: Are you looking for a simple and easy to maintain social login authentication code for your Laravel application? Well, this step by step tutorial might help you to solve that problem. The full check might look like: data_check_string =. You can verify the authentication and the integrity of the data received by comparing the received hash parameter with the hexadecimal representation of the HMAC-SHA-256 signature of the data-check-string with the SHA256 hash of the bot's token used as a secret key.ĭata-check-string is a concatenation of all received fields, sorted in alphabetical order, in the format key= with a line feed character ('\n', 0x0A) used as separator – e.g., 'auth_date=\nfirst_name=\nid=\nusername='. by calling the callback function data-onauth with the JSON-object containing id, first_name, last_name, username, photo_url, auth_date and hash fields.by redirecting the user to the URL specified in the data-auth-url attribute with the following parameters: id, first_name, last_name, username, photo_url, auth_date and hash.After a successful authorization, the widget can return data in two ways:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |