Download the PHP package gigablah/silex-oauth without Composer
On this page you can find all versions of the php package gigablah/silex-oauth. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gigablah/silex-oauth
More information about gigablah/silex-oauth
Files in gigablah/silex-oauth
Package silex-oauth
Short Description Silex OAuth Authentication Provider
License MIT
Homepage https://github.com/gigablah/silex-oauth
Informations about the package silex-oauth
OAuthServiceProvider
The OAuthServiceProvider integrates the lusitanian/oauth library with the Security component to provide social logins for the Silex microframework.
This library only provides the authentication system. You would have to supply your own user provider, or you can make use of the in-memory provider for testing.
Features
- Supports most popular providers such as Facebook, Twitter, Google and GitHub
- Extensible via event hooks so you can plug in your own listeners and user providers
- Supports optional CSRF protection mechanism
Example
Check out the demo application for a code example.
Installation
Use Composer to install the gigablah/silex-oauth library by adding it to your composer.json
.
You should use a version that is compatible with your Silex installation.
Take note that the versions specified for symfony/security
(or any other Symfony component) in the examples below are based on compatibility with Silex. OAuthServiceProvider itself should be compatible with component versions from 2.3.0 onwards (please open an issue if this is not the case).
Silex 2.0
Silex 1.3
Silex 1.0
Usage
First, you need to register the service provider and configure it with the application keys, secrets, scopes and user API endpoints for each OAuth provider you wish to support. Some examples are shown below:
Next, register the oauth
authentication provider in your firewall.
Note that the library assumes the default login, callback and check paths to be prefixed with /auth
, so this path needs to be secured. You can uncomment the path options and change the defaults.
You will need to configure each of your OAuth providers with the correct absolute callback_path
. For example, the default callback for Facebook would be http://your.domain/auth/facebook/callback
.
Finally, you can provide a login/logout interface. This example assumes usage of the Twig templating engine:
The template itself:
Custom Event Handlers
Two default event listeners are registered by default:
UserInfoListener
executes right after an OAuth access token is successfully generated. The security token is then populated with user profile information from the configured API endpoint.UserProviderListener
executes at the point where the authentication provider queries for a user object from the user provider.
Depending on your application, you might want to automatically register OAuth users who do not already have an existing user account. This can be done by overriding UserProviderListener
and placing your registration code in the listener function, or by simply registering a separate listener in the chain.
Custom Services
You can register your own services or override existing ones by manually specifying the class to instantiate:
License
Released under the MIT license. See the LICENSE file for details.