Skip to content

bithai/socialite

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Socialite

Getting Started (BETA - Laravel 5.0+)

Add Configuration

First, you should configure the authentication providers you would like to use in your config/services.php file.

'twitter' => [
	'client_id' => 'your-client-id',
	'client_secret' => 'your-client-secret',
	'redirect' => 'http://yourapp.com/auth/twitter/callback'
],

Redirect To The OAuth Provider

	<?php

	use Laravel\Socialite\Contracts\Factory as SocialiteFactory;

	class YourController extends BaseController {

		public function __construct(SocialiteFactory $socialite)
		{
			$this->socialite = $socialite;
		}

		public function redirectToTwitter()
		{
			return $this->socialite->driver('twitter')->redirect();
		}

	}

You may also add scopes to the authentication call:

	public function redirectToTwitter()
	{
		return $this->socialite->driver('twitter')
                            ->scopes(['scope1', 'scope2'])
                            ->redirect();
	}

Capture The User Details

After the user accepts the authentication prompt on the provider:

	<?php

	use Laravel\Socialite\Contracts\Factory as SocialiteFactory;

	class YourController extends BaseController {

		public function __construct(SocialiteFactory $socialite)
		{
			$this->socialite = $socialite;
		}

		public function getUserDetails()
		{
			$user = $this->socialite->driver('twitter')->user();
		}

	}

The user method returns an implementation of Laravel\Cashier\Contracts\User.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%