socialconnect/auth
Social Connect Auth Component
2.1.1
2018-08-29 11:35 UTC
Requires
- php: >=7.0
- ext-json: *
- socialconnect/common: ^1.1
Requires (Dev)
- squizlabs/php_codesniffer: ~3.0.1
- phpunit/phpunit: ^6.5.8
Replaces
- socialconnect/oauth1: 2.1.1
- socialconnect/oauth2: 2.1.1
- socialconnect/openid: 2.1.1
- socialconnect/openid-connect: 2.1.1
- socialconnect/provider: 2.1.1
- dev-master
- 2.1.1
- 2.1.0
- 2.0.0
- 1.x-dev
- 1.13.1
- 1.13.0
- 1.12.0
- 1.11.1
- 1.11.0
- 1.10.0
- 1.9.0
- 1.8.0
- 1.7.0
- 1.6.0
- 1.5.1
- 1.5.0
- 1.4.0
- 1.3.0
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.0
- 1.0.x-dev
- 1.0.1
- 1.0.0
- 0.4.8
- 0.4.7
- 0.4.6
- 0.4.5
- 0.4.4
- 0.4.3
- 0.4.2
- 0.4.1
- 0.4.0
- 0.3.3
- 0.3.2
- 0.3.1
- 0.3
- 0.2.1
- 0.2
- 0.1.6
- 0.1.5
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1
- dev-session-cli
- dev-scrutinizer-patch-1
- dev-cache
README
Open source social sign on PHP. Connect your application(s) with social network(s).
Code examples you can find in example directory
Demo https://sc.lowl.io/
Supported type of providers
- OAuth1 spec RFC 5849
- OAuth2 spec RFC 6749
- OpenID v1 (1.1) (WIP!) spec
- OpenID v2 spec
- OpenID Connect (1.0) spec
- JWT (JSON Web Token) spec RFC 7519
- JWK (JSON Web Keys) spec RFC 7517
Supported providers
OpenId
- PayPal (WIP!)
- Steam
OAuth 1
- 500px
- Tumblr
OAuth 2
- Amazon
- Vk (ВКонтакте)
- GitHub
- GitLab
- Slack
- BitBucket
- Twitch
- Vimeo
- DigitalOcean
- Yandex
- MailRu
- Microsoft (MSN)
- Meetup
- Odnoklassniki
- Discord
- SmashCast
- Steein
- Yahoo!
- Wordpress
OpenIDConnect
- Google (you can use Google from
OAuth2
orOpenIDConnect
) - PixelPin
Installation
The recommended way to install socialconnect/auth
is via Composer.
- If you do not have composer installed, download the
composer.phar
executable or use the installer.
$ curl -sS https://getcomposer.org/installer | php
- Run
php composer.phar require socialconnect/auth
or add a new requirement in your composer.json.
{ "require": { "socialconnect/auth": "^2.0.0" } }
- Run
php composer.phar update
Referenced projects
- OrgHeiglHybridAuth from @heiglandreas - Authentication-layer for your ZendFramework3 App.
- cakephp-social-auth from @ADmad - CakePHP plugin.
- Phalcon-module-skeleton from @ovr - There is a module for Phalcon inside project.
How to use
Composer:
composer install
First you need to setup SocialConnect\Auth\Service
:
$httpClient = new \SocialConnect\Common\Http\Client\Curl(); /** * By default we are using Curl class from SocialConnect/Common * but you can use Guzzle wrapper ^5.3|^6.0 */ //$httpClient = new \SocialConnect\Common\Http\Client\Guzzle( // new \GuzzleHttp\Client() //); /** * Why do we need cache decorator for HTTP Client? * Providers like OpenID & OpenIDConnect require US * to request OpenID specification (and JWK(s) for OpenIDConnect) * * It's not a best practice to request it every time, because it's unneeded round trip to the server * if you are using OpenID or OpenIDConnect we suggest you to use cache * * If you don`t use providers like (Steam) from OpenID or OpenIDConnect * you may skip this because it's not needed */ $httpClient = new \SocialConnect\Common\Http\Client\Cache( $httpClient, /** * Please dont use FilesystemCache for production/stage env, only for local testing! * It doesnot support cache expire (remove) */ new \Doctrine\Common\Cache\FilesystemCache( __DIR__ . '/cache' ) ); $configureProviders = [ 'redirectUri' => 'http://sconnect.local/auth/cb/${provider}/', 'provider' => [ 'facebook' => [ 'applicationId' => '', 'applicationSecret' => '', 'scope' => ['email'], 'options' => [ 'identity.fields' => [ 'email', 'picture.width(99999)' ], ], ], ], ]; $service = new \SocialConnect\Auth\Service( $httpClient, new \SocialConnect\Provider\Session\Session(), $configureProviders ); /** * By default collection factory is null, in this case Auth\Service will create * a new instance of \SocialConnect\Auth\CollectionFactory * you can use custom or register another providers by CollectionFactory instance */ $collectionFactory = null; $service = new \SocialConnect\Auth\Service( $httpClient, new \SocialConnect\Provider\Session\Session(), $configureProviders, $collectionFactory );
Next create you loginAction:
$providerName = 'facebook'; $provider = $service->getProvider($providerName); header('Location: ' . $provider->makeAuthUrl());
And implement callback handler:
$providerName = 'facebook'; $provider = $service->getProvider($providerName); $accessToken = $provider->getAccessTokenByRequestParameters($_GET); var_dump($accessToken); $user = $provider->getIdentity($accessToken); var_dump($user);
License
This project is open-sourced software licensed under the MIT License.
See the LICENSE file for more information.