2017 © Pedro Peláez
 

symfony-bundle oauth2-client-bundle

Symfony OAuth2ClientBundle

image

jdelaune/oauth2-client-bundle

Symfony OAuth2ClientBundle

  • Friday, April 6, 2018
  • by jdelaune
  • Repository
  • 2 Watchers
  • 4 Stars
  • 2,798 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 14 Versions
  • 7 % Grown

The README.md

OAuth2 Client Bundle

OAuth2 Client Bundle for Symfony 2., (*1)

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., (*2)

Installation

Step 1: Add package to Composer

Add the bundle to your composer.json:, (*3)

``` js { "require": { "jdelaune/oauth2-client-bundle": "dev-master" } }, (*4)


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., (*5)

Step 2: Enable the bundle

Enable the bundle in the kernel:, (*6)

``` php <?php // app/AppKernel.php, (*7)

public function registerBundles() { $bundles = array( // ... new OAuth2\ClientBundle\OAuth2ClientBundle(), ); }, (*8)


### Step 3: Add parameters You'll need add your OAuth2 Server URIs as parameters to your `parameters.yml` ``` yaml # app/config/parameters.yml parameters: oauth2.client.server: authorize_uri: 'http://example.com/authorize' token_uri: 'https://example.com/token' verify_uri: 'https://example.com/verify-token' validate_ssl: true

The verify uri should verify the access token on your OAuth2 Server and provide a JSON encoded array of:, (*9)

  • access_token
  • client_id
  • expires_in
  • user_id (Optional)
  • scope (Optional)

Step 4a: Configure security (access token)

Access token only firewall is most often used for securing APIs where the end user won't actually be interacting with your Symfony application directly., (*10)

You'll need to setup a firewall in your security.yml, (*11)

``` yaml, (*12)

app/config/security.yml

security: encoders: OAuth2\ClientBundle\Security\User\OAuth2User: plaintext, (*13)

providers:
    oauth2_client:
        id: oauth2.client.user_provider

firewalls:
    oauth2_secured:
        pattern: ^/secured_area/
        oauth2_access_token: true
        stateless: true

### Step 4b: Configure security (authorization code) Authorization code firewall is most often used when the end user is interacting with your Symfony application. You'll need to setup a firewall in your `security.yml` ``` yaml # app/config/security.yml security: encoders: OAuth2\ClientBundle\Security\User\OAuth2User: plaintext providers: oauth2_client: id: oauth2.client.user_provider firewalls: oauth2_secured: pattern: ^/secured_area/ oauth2_authorization_code: client_id: ~ client_secret: ~ redirect_uri: http://www.example.com/secured_area/authorized scope: basic

The redirect_uri needs to be a URI behind the same firewall. You can use all the usual configuration options here as well that one would use for the form firewall like use_referer and default_target_path., (*14)

Step 5: Add routing

We provide default routing for some paths needed when using the authorization code firewall. Add this to your routing.yml, (*15)

``` yaml, (*16)

app/config/routing.yml

oauth2_client: resource: "@OAuth2ClientBundle/Controller/" type: annotation prefix: /, (*17)


## The OAuth2Token The client bundle will provide an `OAuth2Token` object for any secured path in your controllers. There are additional getters available on the `OAuth2User` object: ``` php $token = $this->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., (*18)

Scopes will be turned into roles automatically, e.g. a scope of email would result in a role of ROLE_EMAIL., (*19)

There are additional getters available on the OAuth2User object:, (*20)

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, (*21)

The Versions

28/03 2018

4.0.0

4.0.0.0 http://github.com/jdelaune/oauth2-client-bundle

Symfony OAuth2ClientBundle

  Sources   Download

MIT

The Requires

 

oauth security oauth2

28/03 2018

dev-master

9999999-dev http://github.com/jdelaune/oauth2-client-bundle

Symfony OAuth2ClientBundle

  Sources   Download

MIT

The Requires

 

oauth security oauth2

26/06 2017

3.0.0

3.0.0.0 http://github.com/jdelaune/oauth2-client-bundle

Symfony OAuth2ClientBundle

  Sources   Download

MIT

The Requires

 

oauth security oauth2

16/03 2016

1.0.x-dev

1.0.9999999.9999999-dev http://github.com/jdelaune/oauth2-client-bundle

Symfony OAuth2ClientBundle

  Sources   Download

MIT

The Requires

 

oauth security oauth2

16/03 2016

v1.0.1

1.0.1.0 http://github.com/jdelaune/oauth2-client-bundle

Symfony OAuth2ClientBundle

  Sources   Download

MIT

The Requires

 

oauth security oauth2

16/03 2016

2.0.x-dev

2.0.9999999.9999999-dev http://github.com/jdelaune/oauth2-client-bundle

Symfony OAuth2ClientBundle

  Sources   Download

MIT

The Requires

 

oauth security oauth2

16/03 2016

0.4.0

0.4.0.0 http://github.com/jdelaune/oauth2-client-bundle

Symfony OAuth2ClientBundle

  Sources   Download

MIT

The Requires

 

oauth security oauth2

16/03 2016

v2.0.0

2.0.0.0 http://github.com/jdelaune/oauth2-client-bundle

Symfony OAuth2ClientBundle

  Sources   Download

MIT

The Requires

 

oauth security oauth2

16/03 2016

v1.0.0

1.0.0.0 http://github.com/jdelaune/oauth2-client-bundle

Symfony OAuth2ClientBundle

  Sources   Download

MIT

The Requires

 

oauth security oauth2

30/09 2013

v0.3

0.3.0.0 http://github.com/jdelaune/oauth2-client-bundle

Symfony OAuth2ClientBundle

  Sources   Download

MIT

The Requires

 

oauth security oauth2

30/09 2013

v0.2

0.2.0.0 http://github.com/jdelaune/oauth2-client-bundle

Symfony OAuth2ClientBundle

  Sources   Download

MIT

The Requires

 

oauth security oauth2

29/09 2013

v0.1

0.1.0.0 http://github.com/jdelaune/oauth2-client-bundle

Symfony OAuth2ClientBundle

  Sources   Download

MIT

The Requires

 

oauth security oauth2