Package Data | |
---|---|
Maintainer Username: | svensp |
Maintainer Contact: | sps@ipunkt.biz (Sven Speckmaier) |
Package Create Date: | 2014-09-15 |
Package Last Update: | 2015-01-13 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-24 15:05:40 |
Package Statistics | |
---|---|
Total Downloads: | 182 |
Monthly Downloads: | 1 |
Daily Downloads: | 0 |
Total Stars: | 1 |
Total Watchers: | 6 |
Total Forks: | 1 |
Total Open Issues: | 0 |
Social-Auth is a Laravel package which wraps around a oauth library and laravel with the goal to let you simply set the provider credentials and be done.
It currently uses hybrid_auth in the background. With the coming of the new SocialLite package for laravel i will probably switch out hybrid_auth for it.
Add the following lines to your composer.json:
"require": {
"ipunkt/social-auth": "dev-master"
}
To configure 3 steps are necessary.
If you wish for user deletes to trigger deletion of their mappings to provider accounts make sure to set the
'user table' variable in the config before migrating
Add
'Ipunkt\SocialAuth\SocialAuthServiceProvider'
to your app.php
Publish
php artisan config:publish ipunkt/social-auth
then set your provider credentials in
app/config/packages/ipunkt/social-auth/config.php
Migrate the necessary database tables.
php artisan migrate --package="ipunkt/social-auth"
This package tries not to bring any views of its own, thus error handling is done through the session.
On success, 'message' will be set directly in the Session. e.g. {{ Session::get('message') }}
On error, 'message' will be set in errors. e.g. {{ $errors->first('message') }}
Letting your users log in through a SocialAuth provider is as simple as directing them to the social.login
route with
the name of the provider as parameter.
{{ link_to_route('social.login', 'log in through Facebook', 'Facebook' }}
Allowing your users to register using a provider account requires a little more work.
social.register
route, with the provider name as its parameter. e.g.
{{ link_to_route('social.register', 'register through Facebook', ['Facebook']) }}
Most of the time you will want to provide links to all enabled providers instead of a certain one.
To do this, use SocialAuth::getProviders()
to grab all enabled providers and use *Link($innerHtml) to have it build a link
for you.
Example:
@foreach(SocialAuth::getProviders() as $provider)
if(Auth::check()) {
// A link which lets you attach a user from this provider to your local account
{{ $provider->attachLink($provider->getName()) }}
} else {
// A link which lets you login through this provider
{{ $provider->loginLink($provider->getName()) }}
// A link which lets a user request a running registration to use an account on this provider to login
{{ $provider->registerLink($provider->getName()) }}
}
@endforeach
The Profile is currently dependant on Hybrid_Auth_Profile as the underlying package
ProfileInterface
Function | returned value ------------------- | -------------- getIdentifier | The unique identifier string by which the provider identifies the user getProfileUrl | Profile URL getWebsiteUrl | Website URL getPhotoUrl | Photo URL getDisplayName | Display name or "$firstName $lastName" getDescription | getFirstName | First name getLastName | Last name getGender | Gender getLanguage | Language getAge | Age getBirthDay | Day of Birth getBirthMonth | Month of Birth getBirthYear | Year of Birth getEmail | Email getVerifiedEmail | Verified Email if the provider allows it getPhone | Phone number getAddress | Address getCountry | Country getRegion | Region getCity | City getZip | ZIP or Postal code
There are 3 Ways to access Profiles:
SocialAuth::getProviders()['Facebook']->getProfile()
SocialAuth::getProfile
This will give you the Profile of the currently logged in User with the special 'UserProfile' Provider. It contains the
same data as the first Provider Profile to be registered or attached to this user.EloquentHasProfile
traitYour provider will ask you to set a return url where user logging into your application get sent. This is static: http://path.to/your/laravel/installation/social/auth
To switch out Eloquent for the ORM of your choice do the following
Create a model which implements the SocialLoginInterface Create a repository which implements the SocialLoginrepository interface
bind this repository to 'Ipunkt\SocialAuth\SocialLoginInterface' in the Laravel IoC
Create a repository which implements the UserRepository interface
bind this repository to 'Ipunkt\SocialAuth\Repositories\UserRepository' in the Laravel IoC