dotkernel / dot-auth-social
Authentication wrapper for social providers, with PSR-11 factories
Requires
- php: ~8.3.0 || ~8.4.0 || ~8.5.0 || ~8.6.0
- league/oauth2-client: ^2.6
- league/oauth2-facebook: ^2.2
- psr/container: ^1.1 || ^2.0
Requires (Dev)
- laminas/laminas-coding-standard: ^3.0
- phpstan/phpstan: ^2.1
- phpstan/phpstan-phpunit: ^2.0
- phpunit/phpunit: ^12.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Dotkernel's component, used to authenticate users through Facebook and return credentials and user details.
dot-auth-social is a wrapper on top of thephpleague/oauth2-client social providers.
Documentation
Documentation is available at: https://docs.dotkernel.org/dot-auth-social/.
Versions
| Version | Branch | PHP | Status |
|---|---|---|---|
| 2.x | 2.0 |
8.3, 8.4, 8.5, 8.6 | Active |
| 1.x | 1.0 |
8.2, 8.3, 8.4, 8.5 | Security fixes only |
To upgrade from 1.x, read Upgrading from 1.x to 2.x.
Badges
Requirements
- PHP: 8.3, 8.4, 8.5 or 8.6
- Container: a PSR-11 container that accepts one factory for each service key, for example Laminas Service Manager
If your application uses Laminas Service Manager, require laminas/laminas-servicemanager in your application.
Installation
Run this command in your project directory:
composer require dotkernel/dot-auth-social
Then add Dot\AuthSocial\ConfigProvider to your configuration aggregate.
Configuration
Create the file config/autoload/social-authentication.local.php with this content:
<?php declare(strict_types=1); return [ 'social_authentication' => [ 'facebook' => [ 'client_id' => '', 'client_secret' => '', 'redirect_uri' => '', 'graph_api_version' => '', ], ], ];
Put your credentials in the array. All four keys are required.
Usage
Inject Dot\AuthSocial\Service\AuthenticationServiceInterface in your handler.
- Call
getAuthorizationUrl(), keepgetState()in the session, and redirect the user to the URL. - On the callback, compare the
statequery parameter with the value in the session. Stop the login if they are not the same. - Call
authenticate($code)with thecodequery parameter. - Check
isValid()on the result. UsegetIdentity()orgetArrayCopy()for the user details.
The usage page has a full example handler.