Download the PHP package bkstar123/social-auth without Composer
On this page you can find all versions of the php package bkstar123/social-auth. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bkstar123/social-auth
More information about bkstar123/social-auth
Files in bkstar123/social-auth
Package social-auth
Short Description A thin wrapper of Socialite package for an easy implementation of the social login for Laravel applications
License MIT
Informations about the package social-auth
laravel-social-auth
Laravel provides an official package named as Socialite to enable an easy implementation of the social login feature. Although, it is absolutely convenient and simple, it still requires some non trivial piece of code.
Sometimes, the repetitious work can cause an inertia for you to start a new project. To eliminate this issue and quickly gain a momentum for a new idea, this package is built to provide a thin layer wrapping over the Socialite package for the even easier implementation of the social login for a Laravel application.
1 Requirements
It is recommended to install this package with PHP version 7.1.3+ and Laravel Framework version 5.5+
2 Installation
composer require bkstar123/social-auth
3 Usage
3.1 Default usage
This package is by default assumed to be used together with the Laravel's default authentication guard (as specified in ) and model.
- Modify Laravel's default user migration yyyy-mm-dd-xxxxxxxx_create_users_table to make sure it has the following lines:
Note: If you already run the user migration, you should create another migration to update table with the new column and set & columns to be nullable (, are already supplied in the Laravel default user migration), for example:
Run:
yyyy_mm_dd_xxxxxxxx_update_users_table.php:
- Run:
-
Run migration command:
-
In , import and use trait. Add to array, like:
- In , make it to implement interface, then import and use trait
-
In , add the following routes:
-
In the view file where you have the login form, add a social login link, for example:
- In .env file, add the necessary environment keys/values:
Where can be GOOGLE, FACEBOOK, TWITTER, LINKEDIN, GITHUB, GITLAB, BITBUCKET.
3.2 Custom usage
3.2.1 If you do not want to use the package default migration:
-
Put the following key/value in the .env file:
- Then, you must create your own migration file for building a table to store social accounts, for example:
yyyy_mm_dd_xxxxxxxx_create_customer_social_accounts_table.php:
Note: , are required to be named as they are in the migration, the foreign key ( in the above example) can be named appropriately depending on your use cases.
Alternatively, you can publish the package's default migration to and use it as a starting point for customization.
=> Run:
- Run
3.2.2 You can define your custom social account model which has a relationship with your custom user model
app/Models/CustomerSocialAccount.php:
3.2.3 You can also tell the package to use your custom social account and user models
For example:
- In your user model like :
After importing and using trait, add the following method:
- In the controller which handles the login logic:
After making it to implement interface, importing and using trait. Add the following methods:
3.2.4 You can change which kind of the social data you want to map to the user which is to be persisted to the database
For example:
Assuming that your table has , . Then, in the controller which handles the login logic, add the following method:
3.2.5 You can use beforeFirstSocialLogin() hook to add more business logic before signing in a user using her social account at the first time
For example, you may need to set for a user before signing her in using her social account at the first time if your application enforces a logic that all users must be verified before being able to use some features.
To do so, in the controller which handles the login logic, add the following method:
3.2.6 You can customize the action that is to be taken after successfully signing in a user using her social account
For example: You may want to explicitly redirect the authenticated user to a dashboard
3.2.7 You can customize the action that is to be taken if your application fails to get data from the social provider
For example: You may want to redirect the user to the customer login page in this case
By default, the package uses the Laravel's default authentication guard which is specified in .
This behavior can be overwritten by the method defined in your controller (which handles the login logic):
For example: You may want the package to use the custom authentication guard named as