PHPackages                             idci/guzzle-bundle-knpu-oauth2-plugin - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. idci/guzzle-bundle-knpu-oauth2-plugin

ActiveSymfony-bundle[HTTP &amp; Networking](/categories/http)

idci/guzzle-bundle-knpu-oauth2-plugin
=====================================

This bundle integrates KnpU OAuth2 functionality using a Guzzle Bundle plugin.

v1.0.0(2y ago)0302MITPHP

Since Oct 4Pushed 2y ago1 watchersCompare

[ Source](https://github.com/IDCI-Consulting/guzzle-bundle-knpu-oauth2-plugin)[ Packagist](https://packagist.org/packages/idci/guzzle-bundle-knpu-oauth2-plugin)[ RSS](/packages/idci-guzzle-bundle-knpu-oauth2-plugin/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (9)Versions (2)Used By (0)

Guzzle Bundle KnpU OAuth2 Plugin
================================

[](#guzzle-bundle-knpu-oauth2-plugin)

This bundle integrates KnpU OAuth2 functionality using a Guzzle Bundle plugin.

This bundle was highly inspired by the work of this: [gregurco/guzzle-bundle-oauth2-plugin](https://github.com/gregurco/GuzzleBundleOAuth2Plugin). The OAuth2 negociation to retrieved the AccessToken is handle with [knpuniversity/oauth2-client-bundle](https://github.com/knpuniversity/oauth2-client-bundle) and [league/oauth2-client](https://oauth2-client.thephpleague.com/).

Installation
------------

[](#installation)

With composer:

```
$ composer require idci/guzzle-bundle-knpu-oauth2-plugin

```

Enable bundle
-------------

[](#enable-bundle)

Overrides the `registerBundles` function in `src/Kernel.php` like this:

```
    public function registerBundles(): iterable
    {
        $contents = require $this->getBundlesPath();
        foreach ($contents as $class => $envs) {
            if ($envs[$this->environment] ?? $envs['all'] ?? false) {
                if ($class === \EightPoints\Bundle\GuzzleBundle\EightPointsGuzzleBundle::class) {
                    yield new $class([
                        new \IDCI\Bundle\GuzzleBundleKnpUOAuth2Plugin\IDCIGuzzleBundleKnpUOAuth2Plugin(),
                    ]);
                } else {
                    yield new $class();
                }
            }
        }
    }
```

Configuration
-------------

[](#configuration)

Configure your KnpUOAuth2 client as described into [the offical documentation](https://github.com/knpuniversity/oauth2-client-bundle#configuration) into `config/packages/knpu_oauth2_client.yaml`. Here is an example using a Keycloak client:

```
knpu_oauth2_client:
    clients:
        my_keycloak_client:
            type: keycloak
            auth_server_url: '%env(string:KEYCLOAK_SERVER_BASE_URL)%'
            realm: '%env(string:KEYCLOAK_REALM)%'
            client_id: '%env(string:KEYCLOAK_CLIENT_ID)%'
            client_secret: '%env(string:KEYCLOAK_CLIENT_SECRET)%'
            redirect_route: null
            redirect_params: { }
            # encryption_algorithm: null # Optional: Encryption algorith, i.e. RS256
            # encryption_key_path: null # Optional: Encryption key path, i.e. ../key.pem
            # encryption_key: null # Optional: Encryption key, i.e. contents of key or certificate
            # version: '20.0.1' # Optional: The keycloak version to run against
            # use_state: false # whether to check OAuth2 "state": defaults to true
```

Then when you wants to automatically add a bearer token to your Guzzle client request, simply use the `knpu_oauth2` plugin configuration into `config/packages/eight_points_guzzle.yaml`. Here is an example that use the `my_keycloak_client` KnpUOAuth2 client:

```
eight_points_guzzle:
    clients:
        my_guzzle_client:
            base_url: '%env(string:MY_GUZZLE_CLIENT_ENV_BASE_URL)%'
            options:
                auth: knpu_oauth2
            plugin:
                knpu_oauth2:
                    client: my_keycloak_client
```

If you wants to store your bearer token, you can use the `persistent` option to true. By default this bundle use the `cache.app` service to store the bearer token, but you can change this with the `cache_service_id` option. Here is an example that store your bearer token using a custom `Symfony\Component\Cache\Adapter\RedisAdapter` service.

`config/services.yaml`:

```
services:
    app.redis_provider:
        class: \Redis
        factory: ['Symfony\Component\Cache\Adapter\RedisAdapter', 'createConnection']
        arguments:
            - 'redis://%env(resolve:REDIS_HOST)%'

    app.cache.adapter.redis.keycloak:
        parent: 'cache.adapter.redis'
        tags:
            - { name: 'cache.pool', namespace: 'KEYCLOAK' }
```

`config/packages/cache.yaml`:

```
framework:
    cache:
        pools:
            app.keycloak.cache:
                default_lifetime: 600 # Ten minutes
                adapter: app.cache.adapter.redis.keycloak
                provider: app.redis_provider
```

`config/packages/eight_points_guzzle.yaml`:

```
eight_points_guzzle:
    clients:
        my_guzzle_client:
            base_url: '%env(string:MY_GUZZLE_CLIENT_ENV_BASE_URL)%'
            options:
                auth: knpu_oauth2
            plugin:
                knpu_oauth2:
                    client: my_keycloak_client
                    persistent: true
                    cache_service_id: app.keycloak.cache
```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

950d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/cd741a0b8b7ed0a96db8a20eab052ed110453ed38700091f63ce9db3c5ea8fb8?d=identicon)[idciconsulting](/maintainers/idciconsulting)

---

Top Contributors

[![konandrum](https://avatars.githubusercontent.com/u/964354?v=4)](https://github.com/konandrum "konandrum (11 commits)")

---

Tags

jwtpluginGuzzleoauth2BearerKnpU

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/idci-guzzle-bundle-knpu-oauth2-plugin/health.svg)

```
[![Health](https://phpackages.com/badges/idci-guzzle-bundle-knpu-oauth2-plugin/health.svg)](https://phpackages.com/packages/idci-guzzle-bundle-knpu-oauth2-plugin)
```

###  Alternatives

[nelmio/api-doc-bundle

Generates documentation for your REST API from attributes

2.3k63.6M233](/packages/nelmio-api-doc-bundle)[auxmoney/opentracing-bundle-core

Symfony Opentracing bundle to easily enable distributed tracing

25904.4k9](/packages/auxmoney-opentracing-bundle-core)[chameleon-system/chameleon-base

The Chameleon System core.

1026.5k3](/packages/chameleon-system-chameleon-base)[gregurco/guzzle-bundle-oauth2-plugin

OAuth2 Plugin for Guzzle Bundle, a PHP HTTP client library and framework for building RESTful web service clients

13348.3k](/packages/gregurco-guzzle-bundle-oauth2-plugin)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
