Skip to content

Socialite is a package of OAuth 2 authentication that extracts from laravel/socialite.

License

Notifications You must be signed in to change notification settings

136216444/socialite

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Socialite

Build Status Latest Stable Version Latest Unstable Version Total Downloads License

Socialite is a package of OAuth 2 Authentication that extracts from laravel/socialite. You can easily use it without Laravel.

Install

$ composer require overtrue/socialite

Usage

authorize.php:

<?php

use Overtrue\Socialite\SocialiteManager;

include __DIR__.'/vendor/autoload.php';

$config = [
    'weibo' => [
        'client_id'     => 'your-app-id',
        'client_secret' => 'your-app-secret',
        'redirect'      => 'http://localhost/socialite/callback.php',
    ],
];

$socialite = new SocialiteManager($config);

$response = $socialite->driver('weibo')->redirect();

echo $response;// or $response->send();

callback.php:

<?php

// ...
$user = $socialite->driver('weibo')->user();

var_dump($user);
// 'id' => int 2193182644
// 'nickname' => null
// 'name' => string '安正超' (length=9)
// 'email' => null
// 'avatar' => string 'http://tp1.sinaimg.cn/2193182644/180/40068307042/1' (length=50)

Scope

Before redirecting the user, you may also set "scopes" on the request using the scope method. This method will overwrite all existing scopes:

$response = $socialite->driver('github')
                ->scopes(['scope1', 'scope2'])->redirect();

Additional parameters

To include any optional parameters in the request, call the with method with an associative array:

$response = $socialite->driver('google')
                    ->with(['hd' => 'example.com'])->redirect();

User interface

$user = $socialite->driver('weibo')->user();

$user->getId();
$user->getNickname();
$user->getName();
$user->getEmail();
$user->getAvatar();

License

MIT

About

Socialite is a package of OAuth 2 authentication that extracts from laravel/socialite.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%