Code Monkey home page Code Monkey logo

laravel-oauth2's Introduction

Laravel OAuth 2.0

This is a port to Laravel 4 of Talor Otwell's Laravel-oAuth2 bundle. Which he based on the CodeIgniter OAuth2 Spark maintained by Phil Sturgeon

Authorize users with your application in a driver-base fashion meaning one implementation works for multiple OAuth 2 providers. This is only to authenticate onto OAuth2 providers and not to build an OAuth2 service.

Note that this package ONLY provides the authorization mechanism. There's an example controller below.

Installation via Composer

Add this to you composer.json file, in the require object;

"madewithlove/laravel-oauth2": "0.4.*"

After that, run composer install to install Laravel OAuth 2.0.

Currently Supported

  • Facebook
  • Foursquare
  • GitHub
  • Google
  • iHealth
  • Jawbone
  • Mailchimp
  • Moves
  • Runkeeper
  • Windows Live
  • YouTube

Usage Example

http://example.com/auth/session/facebook

use OAuth2\OAuth2;
use OAuth2\Token_Access;
use OAuth2\Exception as OAuth2_Exception;

public function action_session($provider)
{
	$provider = OAuth2::provider($provider, array(
		'id' => 'your-client-id',
		'secret' => 'your-client-secret',
	));

	if ( ! isset($_GET['code']))
	{
		// By sending no options it'll come back here
		return $provider->authorize();
	}
	else
	{
		// Howzit?
		try
		{
			$params = $provider->access($_GET['code']);
			
        		$token = new Token_Access(array(
        			'access_token' => $params->access_token
        		));
        		$user = $provider->get_user_info($token);

			// Here you should use this information to A) look for a user B) help a new user sign up with existing data.
			// If you store it all in a cookie and redirect to a registration page this is crazy-simple.
			echo "<pre>";
			var_dump($user);
		}
		
		catch (OAuth2_Exception $e)
		{
			show_error('That didnt work: '.$e);
		}
	}
}

laravel-oauth2's People

Contributors

andrew-s avatar caseyamcl avatar crodjer avatar davekelly avatar ericlbarnes avatar jhastingsiii avatar joelstahre avatar jonasvanschoote avatar marekmurawski avatar mathijsjh avatar packagist-sapo avatar prateem avatar stevebauman avatar taylorotwell avatar vlakarados avatar wyred avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.