All Projects → gregurco → GuzzleBundleOAuth2Plugin

gregurco / GuzzleBundleOAuth2Plugin

Licence: MIT license
OAuth2 Plugin for GuzzleBundle

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to GuzzleBundleOAuth2Plugin

guzzle6-bundle
Integrates Guzzle 6 into your Symfony application
Stars: ✭ 11 (-15.38%)
Mutual labels:  guzzle, bundle, symfony-bundle
socketio
No description or website provided.
Stars: ✭ 23 (+76.92%)
Mutual labels:  bundle, symfony-bundle
BeelabTagBundle
🏷 A simple implementation of tags for Symfony and Doctrine ORM
Stars: ✭ 45 (+246.15%)
Mutual labels:  bundle, symfony-bundle
DynamicParametersBundle
[UNMAINTAINED] Runtime retrieval of parameters from environment variables for Symfony
Stars: ✭ 42 (+223.08%)
Mutual labels:  bundle, symfony-bundle
LiipSoapRecorderBundle
[DEPRECATED] Recorder/Player for SOAP communications
Stars: ✭ 12 (-7.69%)
Mutual labels:  bundle, symfony-bundle
breadcrumb-bundle
Symfony bundle for easy breadcrumbs management
Stars: ✭ 26 (+100%)
Mutual labels:  bundle, symfony-bundle
vite-bundle
Integration with your Symfony app & Vite
Stars: ✭ 56 (+330.77%)
Mutual labels:  bundle, symfony-bundle
jsonrpc-bundle
JSON-RPC server for Symfony: exposes services registered in the service container as JSON-RPC-webservices
Stars: ✭ 31 (+138.46%)
Mutual labels:  bundle, symfony-bundle
SinchBundle
📦 Provides integration with Sinch.com SMS API.
Stars: ✭ 12 (-7.69%)
Mutual labels:  bundle, symfony-bundle
supervisor-bundle
Easily update your @Supervisor configuration by using annotations in Symfony commands.
Stars: ✭ 35 (+169.23%)
Mutual labels:  bundle, symfony-bundle
LexikMailerBundle
This Symfony2 bundle allow you to manage some HTML email templates stored in your database. Templates are written with Twig and use I18N. You can also create some layouts to decorate your email.
Stars: ✭ 81 (+523.08%)
Mutual labels:  bundle, symfony-bundle
NucleosDompdfBundle
📜 This bundle provides a wrapper for using dompdf inside symfony.
Stars: ✭ 29 (+123.08%)
Mutual labels:  bundle, symfony-bundle
connect-bundle
No description or website provided.
Stars: ✭ 35 (+169.23%)
Mutual labels:  bundle, symfony-bundle
awsBundle
Symfony AWS Bundle (supports Symfony 2, 3 and 4)
Stars: ✭ 18 (+38.46%)
Mutual labels:  bundle, symfony-bundle
hashed-asset-bundle
Apply an asset version based on a hash of the asset for symfony/asset
Stars: ✭ 24 (+84.62%)
Mutual labels:  bundle, symfony-bundle
OpcacheBundle
Displays the PHP OPcache status in the Symfony profiler toolbar.
Stars: ✭ 21 (+61.54%)
Mutual labels:  bundle, symfony-bundle
SonataFormatterBundle
Symfony SonataFormatterBundle
Stars: ✭ 78 (+500%)
Mutual labels:  bundle, symfony-bundle
SonataDoctrineMongoDBAdminBundle
Symfony Sonata / Integrate Doctrine MongoDB ODM into the SonataAdminBundle
Stars: ✭ 64 (+392.31%)
Mutual labels:  bundle, symfony-bundle
LiipImagineSerializationBundle
Provides integration between LiipImagineBundle and JMSSerializerBundle
Stars: ✭ 24 (+84.62%)
Mutual labels:  bundle, symfony-bundle
wordpress-bundle
Use Wordpress and Symfony together using a Symfony bundle
Stars: ✭ 30 (+130.77%)
Mutual labels:  bundle, symfony-bundle

Guzzle Bundle OAuth2 Plugin

Build Status Coverage Status SensioLabsInsight

This plugin integrates OAuth2 functionality into Guzzle Bundle, a bundle for building RESTful web service clients.


Prerequisites

Installation

To install this bundle, run the command below on the command line and you will get the latest stable version from Packagist.

composer require gregurco/guzzle-bundle-oauth2-plugin

Usage

Enable bundle

Find next lines in src/Kernel.php:

foreach ($contents as $class => $envs) {
    if (isset($envs['all']) || isset($envs[$this->environment])) {
        yield new $class();
    }
}

and replace them by:

foreach ($contents as $class => $envs) {
    if (isset($envs['all']) || isset($envs[$this->environment])) {
        if ($class === \EightPoints\Bundle\GuzzleBundle\EightPointsGuzzleBundle::class) {
            yield new $class([
                new \Gregurco\Bundle\GuzzleBundleOAuth2Plugin\GuzzleBundleOAuth2Plugin(),
            ]);
        } else {
            yield new $class();
        }
    }
}

Basic configuration

With default grant type (client)

# app/config/config.yml

eight_points_guzzle:
    clients:
        api_payment:
            base_url: "http://api.domain.tld"
            
            options:
                auth: oauth2

            # plugin settings
            plugin:
                oauth2:
                    base_uri:       "https://example.com"
                    token_url:      "/oauth/token"
                    client_id:      "test-client-id"
                    client_secret:  "test-client-secret" # optional
                    scope:          "administration"

With password grant type

# app/config/config.yml

eight_points_guzzle:
    clients:
        api_payment:
            base_url: "http://api.domain.tld"
            
            options:
                auth: oauth2

            # plugin settings
            plugin:
                oauth2:
                    base_uri:       "https://example.com"
                    token_url:      "/oauth/token"
                    client_id:      "test-client-id"
                    username:       "johndoe"
                    password:       "A3ddj3w"
                    scope:          "administration"
                    grant_type:     "Sainsburys\\Guzzle\\Oauth2\\GrantType\\PasswordCredentials"

With client credentials in body

# app/config/config.yml

eight_points_guzzle:
    clients:
        api_payment:
            base_url: "http://api.domain.tld"
            
            options:
                auth: oauth2

            # plugin settings
            plugin:
                oauth2:
                    base_uri:       "https://example.com"
                    token_url:      "/oauth/token"
                    client_id:      "test-client-id"
                    scope:          "administration"
                    auth_location:  "body"

Options

Key Description Required Example
base_uri URL of oAuth2 server. yes https://example.com
token_url The path that will be concatenated with base_uri.
Default: /oauth2/token
no /oauth/token
client_id The client identifier issued to the client during the registration process yes s6BhdRkqt3
client_secret The client secret no 7Fjfp0ZBr1KtDRbnfVdmIw
username The resource owner username for PasswordCredentials grant type johndoe
password The resource owner password for PasswordCredentials grant type A3ddj3w
auth_location The place where to put client_id and client_secret in auth request.
Default: headers. Allowed values: body, headers.
no body
resource The App ID URI of the web API (secured resource) no https://service.contoso.com/
private_key Path to private key for JwtBearer grant type "%kernel.root_dir%/path/to/private.key"
scope One or more scope values indicating which parts of the user's account you wish to access no administration
audience no
grant_type Grant type class path. Class should implement GrantTypeInterface.
Default: Sainsburys\\Guzzle\\Oauth2\\GrantType\\ClientCredentials
no Sainsburys\\Guzzle\\Oauth2\\GrantType\\PasswordCredentials
Sainsburys\\Guzzle\\Oauth2\\GrantType\\AuthorizationCode
Sainsburys\\Guzzle\\Oauth2\\GrantType\\JwtBearer
persistent Token will be stored in session unless grant_type is client credentials; in which case it will be stored in the app cache.
Default: false
no
retry_limit How many times request will be repeated on failure.
Default: 5
no

See more information about middleware here.

License

This middleware is licensed under the MIT License - see the LICENSE file for details

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].