2017 © Pedro Peláez
 

laravel-package social-login

Laravel authentication with Social Services API

image

cresjie/social-login

Laravel authentication with Social Services API

  • Tuesday, February 2, 2016
  • by cresjie
  • Repository
  • 1 Watchers
  • 5 Stars
  • 37 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Social Login

Laravel 4 Authentication with Social Services API (OAuth2) like Google, Facebook, Yahoo, Github, (*1)


Installation via Composer

Add this to your composer.json file, in the require object:, (*2)

 "cresjie/social-login": "v1.0.0.0"

After that, run composer install to install the package., (*3)

Add the service provider to app/config/app.php, within the providers array., (*4)

 'providers' => array(
    ...
    'Cresjie\SocialLogin\SocialLoginServiceProvider'
)

Configuration

Publish the default config file to your application so you can make modifications., (*5)

$ php artisan config:publish cresjie/social-login

Add your service provider credentials to the published config file:, (*6)

 app/config/packages/cresjie/social-login/config.php

for formality set your redirect callback credential to something like: www.mysite.com/login/google/callback see **Basic usage -> Authentication **, (*7)

BASIC USAGE

Login Page

Route::get('/login/{provider}',function($provider){
    return SocialLogin::login($provider);
});

where provider is a social service like google, facebook, etc.. this would redirect the user to the login page for the that social service., (*8)

Authentication

Route::get('/login/{provider}/callback',function($provider){
    var_dump( SocialLogin::authenticate($provider) );
});

after the user logs in to his social service. He/she will be redirected to the url specified in your config file redirect, and just call the SocialLogin::authenticate($provider) to retrieve information, (*9)

Other Usage

you can also filter results in the config file to have uniform calls. For example retrieving profile picture in google has an array key of picture while in github has an array key of avatar_url, (*10)

Route::get('/login/{provider}/callback',function($provider){
    $results = SocialLogin::authenticate($provider);

    echo $results['picture']; // for goole
    echo $results['avatar_url']; //for github

});

how about a uniform call., (*11)

Route::get('/login/{provider}/callback',function($provider){
    $results = SocialLogin::authenticate($provider);

    echo $results['image']; //uniform call

});

how? just set filter_result in the config file with something like:, (*12)

<?php
    return [
        'google' => [
                ...
                'filter_result' => function($result){
                    $result['image'] = $result['picture'];
                    return $result; //should have return value
                }
        ],

        'github' => [
            ...
            'filter_result' => function($result){
                $result['image'] = $result['avatar_url'];
                return $result;
            }
        ]
];

we've just add another key to the result value to have a uniform call.. cool!, (*13)

Access Token

After the user successfully authenticate the login. You can get the access token by calling the method: SocialLogin::getAccessToken(), (*14)

The Versions

02/02 2016

dev-master

9999999-dev https://github.com/cresjie/social-login

Laravel authentication with Social Services API

  Sources   Download

MIT

The Requires

 

by Cres Jie

laravel social oauth google oauth2 facebook github yahoo social-login sociallogin

25/02 2015

1.0.0.0

1.0.0.0

Laravel authentication with Social Services API

  Sources   Download

The Requires

 

by Cres Jie

laravel social oauth google oauth2 facebook github yahoo social-login sociallogin