Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jdelaune/oauth2-client-bundle
Symfony 2-4 OAuth2 Client Bundle
https://github.com/jdelaune/oauth2-client-bundle
oauth2 oauth2-client symfony symfony2 symfony3 symfony4
Last synced: 24 days ago
JSON representation
Symfony 2-4 OAuth2 Client Bundle
- Host: GitHub
- URL: https://github.com/jdelaune/oauth2-client-bundle
- Owner: jdelaune
- License: mit
- Created: 2013-09-12T13:45:43.000Z (about 11 years ago)
- Default Branch: 3.x
- Last Pushed: 2019-12-17T12:11:43.000Z (almost 5 years ago)
- Last Synced: 2024-09-30T16:01:38.402Z (about 1 month ago)
- Topics: oauth2, oauth2-client, symfony, symfony2, symfony3, symfony4
- Language: PHP
- Homepage:
- Size: 40 KB
- Stars: 5
- Watchers: 2
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Security: Security/Authentication/Provider/OAuth2Provider.php
Awesome Lists containing this project
README
# OAuth2 Client Bundle
OAuth2 Client Bundle for Symfony 2-5.
## Overview
Allow for the protection of resources via OAuth2. Provides two Symfony firewalls. One for checking bearer access tokens for securing API application. The access tokens can be provided via a header (recommended) or query e.g. `Authorization: Bearer {Access Token}` or `http://example.com/resource?access_token={Access Token}`. The other firewall is for securing web applications via the authorization code grant type.
## Installation
### Step 1: Add package to Composer
Add the bundle to your composer.json:
``` js
{
"require": {
"jdelaune/oauth2-client-bundle": "^5.0"
}
}
```Now tell composer to download the bundle by running the command:
``` bash
$ php composer.phar update jdelaune/oauth2-client-bundle
```Composer will install the bundle to your project's `vendor/jdelaune` directory.
### Step 2: Enable the bundle
Enable the bundle in the kernel:
``` php
get('security.context')->getToken();
$token->getAccessToken(); // The access token
$token->getRefreshToken(); // The refresh token
$token->getExpiresAt(); // Expiry datetime object
$token->getExpiresIn(); // Seconds until the access token expires
```## The OAuth2User
The client bundle will provide an `OAuth2User` object for any secured path in your controllers.
Scopes will be turned into roles automatically, e.g. a scope of `email` would result in a role of `ROLE_EMAIL`.
There are additional getters available on the `OAuth2User` object:
``` php
$user = $this->getUser();
$user->getClientId(); // Client ID
$user->getUserId(); // User ID
$user->isUser(); // True if user, false if client only
$user->getUsername(); // Client ID if client only, or User ID if user
$user->getScopes(); // Array of scopes
$user->getAccessToken(); // The access token
```