Skip to content

Commit

Permalink
First commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Nov 30, 2015
0 parents commit c43dc30
Show file tree
Hide file tree
Showing 26 changed files with 2,526 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/vendor
composer.phar
composer.lock
.DS_Store
/.idea
Thumbs.db
/*.php
sftp-config.json
32 changes: 32 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

$header = <<<EOF
This file is part of the overtrue/socialite.
(c) overtrue <i@overtrue.me>
This source file is subject to the MIT license that is bundled
with this source code in the file LICENSE.
EOF;

Symfony\CS\Fixer\Contrib\HeaderCommentFixer::setHeader($header);

return Symfony\CS\Config\Config::create()
// use default SYMFONY_LEVEL and extra fixers:
->fixers(array(
'header_comment',
'short_array_syntax',
'ordered_use',
'php_unit_construct',
'php_unit_strict',
// 'strict',
// 'strict_param',
'align_double_arrow',
'align_equals'
))
->finder(
Symfony\CS\Finder\DefaultFinder::create()
->exclude('vendor')
->in(__DIR__)
)
;
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
language: php

php:
- 5.5
- 5.6
- hhvm

sudo: false

install: travis_retry composer install --no-interaction --prefer-source

script: vendor/bin/phpunit --verbose
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) overtrue <i@overtrue.me>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Socialite

Socialite is a collection of OAuth 2 packages that extracts from [laravel/socialite](https://github.com/laravel/socialite).

# Install

```shell
$ composer require overtrue/socialite
```

# Usage

`authorize.php`:

```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);

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

`callback.php`:

```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)
```

# License

MIT
26 changes: 26 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "overtrue/socialite",
"description": "Weibo,QQ,WeChat OAuth login provider for laravel/socialite.",
"autoload": {
"psr-4": {
"Overtrue\\Socialite\\": "src/"
}
},
"require": {
"php": ">=5.4.0",
"guzzlehttp/guzzle": "~5.0|~6.0",
"symfony/http-foundation": "v2.*.*"
},
"require-dev": {
"mockery/mockery": "~0.9",
"phpunit/phpunit": "~4.0"
},
"license": "MIT",
"authors": [
{
"name": "overtrue",
"email": "anzhengchao@gmail.com"
}
],
"minimum-stability": "dev"
}
18 changes: 18 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
71 changes: 71 additions & 0 deletions src/AccessToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

/*
* This file is part of the overtrue/socialite.
*
* (c) overtrue <i@overtrue.me>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

/**
* AccessToken.php.
*
* This file is part of the socialite.
*
* (c) overtrue <i@overtrue.me>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Overtrue\Socialite;

use ArrayAccess;
use InvalidArgumentException;

/**
* Class AccessToken.
*/
class AccessToken implements AccessTokenInterface, ArrayAccess
{
use AttributeTrait;

/**
* @var array
*/
protected $attributes;

/**
* AccessToken constructor.
*
* @param array $attributes
*/
public function __construct(array $attributes = [])
{
if (empty($attributes['access_token'])) {
throw new InvalidArgumentException('The key "access_token" could not be empty.');
}

$this->attributes = $attributes;
}

/**
* Return the access token string.
*
* @return string
*/
public function getToken()
{
return $this->getAttribute('access_token');
}

/**
* {@inheritdoc}
*/
public function __toString()
{
return strval($this->getAttribute('access_token', ''));
}
}
36 changes: 36 additions & 0 deletions src/AccessTokenInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/*
* This file is part of the overtrue/socialite.
*
* (c) overtrue <i@overtrue.me>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

/**
* AccessTokenInterface.php.
*
* This file is part of the socialite.
*
* (c) overtrue <i@overtrue.me>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Overtrue\Socialite;

/**
* Interface AccessTokenInterface.
*/
interface AccessTokenInterface
{
/**
* Return the access token string.
*
* @return string
*/
public function getToken();
}
109 changes: 109 additions & 0 deletions src/AttributeTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php

/*
* This file is part of the overtrue/socialite.
*
* (c) overtrue <i@overtrue.me>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

/**
* AttributeTrait.php.
*
* This file is part of the socialite.
*
* (c) overtrue <i@overtrue.me>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Overtrue\Socialite;

/**
* Trait AttributeTrait.
*/
trait AttributeTrait
{
/**
* Return the extra attribute.
*
* @param string $name
* @param null $default
*/
public function getAttribute($name, $default = null)
{
return isset($this->attributes[$name]) ? $this->attributes[$name] : $default;
}

/**
* Set extra attributes.
*
* @param string $name
* @param mixed $value
*
* @return $this
*/
public function setAttribute($name, $value)
{
$this->attributes[$name] = $value;

return $this;
}

/**
* Map the given array onto the user's properties.
*
* @param array $attributes
*
* @return $this
*/
public function merge(array $attributes)
{
$this->attributes = array_merge($this->attributes, $attributes);

return $this;
}

/**
* {@inheritdoc}
*/
public function offsetExists($offset)
{
return array_key_exists($offset, $this->attributes);
}

/**
* {@inheritdoc}
*/
public function offsetGet($offset)
{
return $this->getAttribute($offset);
}

/**
* {@inheritdoc}
*/
public function offsetSet($offset, $value)
{
$this->setAttribute($offset, $value);
}

/**
* {@inheritdoc}
*/
public function offsetUnset($offset)
{
unset($this->attributes[$offset]);
}

/**
* {@inheritdoc}
*/
public function __get($property)
{
return $this->getAttribute($property);
}
}
Loading

0 comments on commit c43dc30

Please sign in to comment.