Giter Site home page Giter Site logo

travisneids / laravel-oauth2 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from madewithlove/laravel-oauth2

0.0 1.0 0.0 104 KB

Authorize users in your application with multiple OAuth 2.0 providers.

Home Page: http://getsparks.org/packages/oauth2/versions/HEAD/show

laravel-oauth2's Introduction

Laravel OAuth 2.0

This is 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 Spark ONLY provides the authorization mechanism. There's an example controller below, however in a later version there will be a full controller.

Installation via Composer

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

"taylorotwell/laravel-oauth2": "0.2.*"

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

Currently Supported

  • Facebook
  • GitHub
  • Google
  • Windows Live
  • YouTube
  • Moves
  • Runkeeper

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

taylorotwell avatar wyred avatar andrew-s avatar caseyamcl avatar ericlbarnes avatar jonasvanschoote avatar crodjer avatar

Watchers

James Cloos 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.