PHP code example of jkbennemann / laravel-4-social-oauth

1. Go to this page and download the library: Download jkbennemann/laravel-4-social-oauth library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jkbennemann / laravel-4-social-oauth example snippets


'providers' => array(
	// ...
	
	'Jkbennemann\OAuth\OAuthServiceProvider',
)

'aliases' => array(
	// ...
	
	'OAuth' => 'Jkbennemann\OAuth\Facade\OAuth',
)

 

return array( 
	
	/*
	|--------------------------------------------------------------------------
	| OAuth Config
	|--------------------------------------------------------------------------
    */

    /*
    |--------------------------------------------------------------------------
    | Note: ${provider} will be resolved automatically accordingly
    |--------------------------------------------------------------------------
    */
	'redirect_base_uri' => 'https://you-callback-url.local/login/${provider}',

	/*
    |--------------------------------------------------------------------------
	| Provider
    |--------------------------------------------------------------------------
	 */
	'provider' => array(

        /**
         * Amazon
         */
        'amazon' => array(
            'applicationId'     => '',
            'applicationSecret' => '',
            'scope'         => array()
        ),

        /**
         * Atlassian
         */
        'atlassian' => array(
            'applicationId'     => '',
            'applicationSecret' => ''
        ),

        /**
         * Bitbucket
         */
        'bitbucket' => array(
            'applicationId'     => '',
            'applicationSecret' => '',
            'scope'         => array(
                'account'
            )
        ),

        /**
         * GitHub
         */
        'github' => array(
            'applicationId'     => '',
            'applicationSecret' => '',
            'scope'         => array(
                'user',
                'email'
            ),
            'options'       => array(
                'fetch_emails'   => true
            )
        ),

    )
);

$service = OAuth::provider('github');

$service = OAuth::provider('Github','http://url.to.redirect.to');

/**
 * Login user with github
 *
 * @return void
 */

public function loginWithGithub() {
	
	// get data from input
	$code = Input::get( 'code' );
	
	// get github service
	$service = OAuth::provider( 'github' );
	
	// check if code is valid
	
	// if code is provided get user data and sign in
	if ( !empty( $code ) ) {
		
        // This was a callback request from github, get the token
        $accessToken  = $service->getAccessTokenByRequestParameters(Input::all());

        // fetch information for authorized token
        $user = $service->getIdentity($accessToken);
        
        var_dump($user);

        //perform user lookup e.g. User::findByEmail($user->email);
        //login User
        //redirect the user to any page
        
        exit();	
	} else {
	    // if not ask for permission first
		// get service authorization
		$url = $service->makeAuthUrl();
		
		// return to auth page
		 return Redirect::to($url);
	}

}
app/config/app.php
app/config/app.php

$ php artisan config:publish jkbennemann/laravel-4-social-oauth