2017 © Pedro Peláez
 

library socialite

A collection of OAuth 2 packages that extracts from laravel/socialite.

image

elichter/socialite

A collection of OAuth 2 packages that extracts from laravel/socialite.

  • Wednesday, June 28, 2017
  • by coreyYii
  • Repository
  • 1 Watchers
  • 0 Stars
  • 10 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 114 Forks
  • 0 Open issues
  • 28 Versions
  • 0 % Grown

The README.md

Socialite

hh Build Status Latest Stable Version Latest Unstable Version Scrutinizer Code Quality Total Downloads License, (*1)

Socialite is an OAuth2 Authentication tool. It is inspired by laravel/socialite, You can easily use it in any PHP project., (*2)

For Laravel 5: overtrue/laravel-socialite, (*3)


 创造不息,交付不止
, (*4)

Requirement

PHP >= 5.4

Installation

$ composer require "overtrue/socialite:~1.0"

Usage

authorize.php:, (*5)

<?php
use Overtrue\Socialite\SocialiteManager;

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

$socialite = new SocialiteManager($config);

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

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

callback.php:, (*6)

<?php

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

$user->getId();        // 1472352
$user->getNickname();  // "overtrue"
$user->getName();      // "安正超"
$user->getEmail();     // "anzhengchao@gmail.com"
...

Configuration

Now we support the following sites:, (*7)

facebook, github, google, linkedin, weibo, qq, wechat, wechat_open, and douban., (*8)

Each drive uses the same configuration keys: client_id, client_secret, redirect., (*9)

Example:, (*10)

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

Special configuration options for WeChat Open Platform, (*11)

'wechat_open' => [
    'client_id'     => 'your-app-id',
    'client_secret' => ['your-component-appid', 'your-component-access-token'],
    'redirect'      => 'http://localhost/socialite/callback.php',
]

Scope

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

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

Redirect URL

You may also want to dynamic set redirect,you can use the following methods to change the redirect URL:, (*13)

$socialite->redirect($url);
// or
$socialite->withRedirectUrl($url)->redirect();
// or
$socialite->setRedirectUrl($url)->redirect();

WeChat scopes: - snsapi_base, snsapi_userinfo - Used to Media Platform Authentication. - snsapi_login - Used to web Authentication., (*14)

Additional parameters

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

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

User interface

Standard user api:


$user = $socialite->driver('weibo')->user();
{
  "id": 1472352,
  "nickname": "overtrue",
  "name": "安正超",
  "email": "anzhengchao@gmail.com",
  "avatar": "https://avatars.githubusercontent.com/u/1472352?v=3",
  "original": {
    "login": "overtrue",
    "id": 1472352,
    "avatar_url": "https://avatars.githubusercontent.com/u/1472352?v=3",
    "gravatar_id": "",
    "url": "https://api.github.com/users/overtrue",
    "html_url": "https://github.com/overtrue",
    ...
  },
  "token": {
    "access_token": "5b1dc56d64fffbd052359f032716cc4e0a1cb9a0",
    "token_type": "bearer",
    "scope": "user:email"
  }
}

You can fetch the user attribute as a array key like this:, (*16)

$user['id'];        // 1472352
$user['nickname'];  // "overtrue"
$user['name'];      // "安正超"
$user['email'];     // "anzhengchao@gmail.com"
...

Or using method:, (*17)

$user->getId();
$user->getNickname();
$user->getName();
$user->getEmail();
$user->getAvatar();
$user->getOriginal();
$user->getToken();// or $user->getAccessToken()

Get original response from OAuth API

The $user->getOriginal() method will return an array of the API raw response., (*18)

Get access token Object

You can get the access token instance of current session by call $user->getToken() or $user->getAccessToken() or $user['token'] ., (*19)

Get user with access token

$accessToken = new AccessToken(['access_token' => $accessToken]);
$user = $socialite->user($accessToken);

Custom Session or Request instance.

You can set the request with your custom Request instance which instanceof Symfony\Component\HttpFoundation\Request., (*20)


$request = new Request(); // or use AnotherCustomRequest. $socialite = new SocialiteManager($config, $request);

Or set request to SocialiteManager instance:, (*21)

$socialite->setRequest($request);

You can get the request from SocialiteManager instance by getRequest():, (*22)

$request = $socialite->getRequest();

Set custom session manager.

By default, the SocialiteManager use Symfony\Component\HttpFoundation\Session\Session instance as session manager, you can change it as following lines:, (*23)

$session = new YourCustomSessionManager();
$socialite->getRequest()->setSession($session);

Your custom session manager must be implement the Symfony\Component\HttpFoundation\Session\SessionInterface., (*24)

Enjoy it! :heart:, (*25)

Reference

License

MIT, (*26)

The Versions

28/06 2017

dev-master

9999999-dev

A collection of OAuth 2 packages that extracts from laravel/socialite.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar overtrue

social oauth login qq wechat weibo

16/05 2017

1.0.25

1.0.25.0

A collection of OAuth 2 packages that extracts from laravel/socialite.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar overtrue

social oauth login qq wechat weibo

08/04 2017

1.0.24

1.0.24.0

A collection of OAuth 2 packages that extracts from laravel/socialite.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar overtrue

social oauth login qq wechat weibo

04/03 2017

1.0.23

1.0.23.0

A collection of OAuth 2 packages that extracts from laravel/socialite.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar overtrue

social oauth login qq wechat weibo

13/02 2017

1.0.22

1.0.22.0

A collection of OAuth 2 packages that extracts from laravel/socialite.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar overtrue

social oauth login qq wechat weibo

19/01 2017

1.0.21

1.0.21.0

A collection of OAuth 2 packages that extracts from laravel/socialite.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar overtrue

social oauth login qq wechat weibo

01/12 2016

1.0.20

1.0.20.0

A collection of OAuth 2 packages that extracts from laravel/socialite.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar overtrue

social oauth login qq wechat weibo

28/11 2016

1.0.19

1.0.19.0

A collection of OAuth 2 packages that extracts from laravel/socialite.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar overtrue

social oauth login qq wechat weibo

12/10 2016

1.0.18

1.0.18.0

A collection of OAuth 2 packages that extracts from laravel/socialite.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar overtrue

social oauth login qq wechat weibo

09/10 2016

1.0.17

1.0.17.0

A collection of OAuth 2 packages that extracts from laravel/socialite.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar overtrue

social oauth login qq wechat weibo

09/10 2016

1.0.16

1.0.16.0

A collection of OAuth 2 packages that extracts from laravel/socialite.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar overtrue

social oauth login qq wechat weibo

03/09 2016

1.0.15

1.0.15.0

A collection of OAuth 2 packages that extracts from laravel/socialite.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar overtrue

social oauth login qq wechat weibo

02/09 2016

1.0.14

1.0.14.0

A collection of OAuth 2 packages that extracts from laravel/socialite.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar overtrue

social oauth login qq wechat weibo

07/07 2016

1.0.13

1.0.13.0

A collection of OAuth 2 packages that extracts from laravel/socialite.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar overtrue

social oauth login qq wechat weibo

07/07 2016

dev-develop

dev-develop

A collection of OAuth 2 packages that extracts from laravel/socialite.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar overtrue

social oauth login qq wechat weibo

28/06 2016

1.0.12

1.0.12.0

A collection of OAuth 2 packages that extracts from laravel/socialite.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar overtrue

social oauth login qq wechat weibo

02/06 2016

1.0.11

1.0.11.0

A collection of OAuth 2 packages that extracts from laravel/socialite.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar overtrue

social oauth login qq wechat weibo

27/03 2016

1.0.10

1.0.10.0

A collection of OAuth 2 packages that extracts from laravel/socialite.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar overtrue

social oauth login qq wechat weibo

11/03 2016

1.0.9

1.0.9.0

A collection of OAuth 2 packages that extracts from laravel/socialite.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar overtrue

social oauth login qq wechat weibo

11/03 2016

1.0.8

1.0.8.0

A collection of OAuth 2 packages that extracts from laravel/socialite.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar overtrue

social oauth login qq wechat weibo

22/02 2016

1.0.7

1.0.7.0

A collection of OAuth 2 packages that extracts from laravel/socialite.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar overtrue

social oauth login qq wechat weibo

15/01 2016

1.0.6

1.0.6.0

A collection of OAuth 2 packages that extracts from laravel/socialite.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar overtrue

social oauth login qq wechat weibo

15/01 2016

1.0.5

1.0.5.0

A collection of OAuth 2 packages that extracts from laravel/socialite.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar overtrue

social oauth login qq wechat weibo

13/01 2016

1.0.4

1.0.4.0

A collection of OAuth 2 packages that extracts from laravel/socialite.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar overtrue

social oauth login qq wechat weibo

11/01 2016

1.0.3

1.0.3.0

A collection of OAuth 2 packages that extracts from laravel/socialite.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar overtrue

social oauth login qq wechat weibo

07/01 2016

1.0.2

1.0.2.0

A collection of OAuth 2 packages that extracts from laravel/socialite.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar overtrue

social oauth login qq wechat weibo

26/12 2015

1.0.1

1.0.1.0

A collection of OAuth 2 packages that extracts from laravel/socialite.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar overtrue

social oauth login qq wechat weibo

10/12 2015

1.0.0

1.0.0.0

A collection of OAuth 2 packages that extracts from laravel/socialite.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar overtrue

social oauth login qq wechat weibo