PHPackages                             cnam/security-jwt-service-provider - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. cnam/security-jwt-service-provider

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

cnam/security-jwt-service-provider
==================================

Service Provider for usage jwt token for auth

2.1.1(9y ago)60108.1k39[4 issues](https://github.com/cnam/security-jwt-service-provider/issues)[2 PRs](https://github.com/cnam/security-jwt-service-provider/pulls)2PHP

Since Jan 8Pushed 9y ago6 watchersCompare

[ Source](https://github.com/cnam/security-jwt-service-provider)[ Packagist](https://packagist.org/packages/cnam/security-jwt-service-provider)[ RSS](/packages/cnam-security-jwt-service-provider/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (25)Used By (2)

Silex security jwt service provider
===================================

[](#silex-security-jwt-service-provider)

[![Build Status](https://camo.githubusercontent.com/d91bac94d3f95edf5d2ff8b458d172705d3429f1ea9d44c76c6f22f52104f62e/68747470733a2f2f7472617669732d63692e6f72672f636e616d2f73656375726974792d6a77742d736572766963652d70726f76696465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/cnam/security-jwt-service-provider)[![Latest Stable Version](https://camo.githubusercontent.com/f33aa28ce778e48c1a6f52965cd3c9c0fc9abc457308c40acbc5259a08f15aae/68747470733a2f2f706f7365722e707567782e6f72672f636e616d2f73656375726974792d6a77742d736572766963652d70726f76696465722f762f737461626c65)](https://packagist.org/packages/cnam/security-jwt-service-provider) [![Total Downloads](https://camo.githubusercontent.com/3df2e78e800fdaf67a195734773d152d680f04a59ee4f1ed642f19c0266088d3/68747470733a2f2f706f7365722e707567782e6f72672f636e616d2f73656375726974792d6a77742d736572766963652d70726f76696465722f646f776e6c6f616473)](https://packagist.org/packages/cnam/security-jwt-service-provider) [![Latest Unstable Version](https://camo.githubusercontent.com/33110717cd71c3e46bd72f05bd24174faf0598cde017a7390c2be0060f84d917/68747470733a2f2f706f7365722e707567782e6f72672f636e616d2f73656375726974792d6a77742d736572766963652d70726f76696465722f762f756e737461626c65)](https://packagist.org/packages/cnam/security-jwt-service-provider) [![License](https://camo.githubusercontent.com/8f1c6de54e0cc374b8cacfc14f93f4dfd0c10b865bfd758beb31b431450e16ba/68747470733a2f2f706f7365722e707567782e6f72672f636e616d2f73656375726974792d6a77742d736572766963652d70726f76696465722f6c6963656e7365)](https://packagist.org/packages/cnam/security-jwt-service-provider)

This provider usage with silex security

require silex

> for usage stable version silex your need used security jwt service provider version in 1.\*

> for usage silex 2.0 version or not stable master your need usage version 2.\*

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

[](#installation)

> composer require cnam/security-jwt-service-provider:1.\*

Or add your composer.json

> require "cnam/security-jwt-service-provider":"1.\*"

Simple example
--------------

[](#simple-example)

### Initialise silex application

[](#initialise-silex-application)

```
require_once __DIR__ . '/../../vendor/autoload.php';

$app = new Silex\Application(['debug' => true]);
```

### Create configuration

[](#create-configuration)

add config for security jwt

```
$app['security.jwt'] = [
    'secret_key' => 'Very_secret_key',
    'life_time'  => 86400,
    'options'    => [
        'username_claim' => 'name', // default name, option specifying claim containing username
        'header_name' => 'X-Access-Token', // default null, option for usage normal oauth2 header
        'token_prefix' => 'Bearer',
    ]
];
```

Create users, any user provider implementing interface UserProviderInterface

```
$app['users'] = function () use ($app) {
    $users = [
        'admin' => array(
            'roles' => array('ROLE_ADMIN'),
            // raw password is foo
            'password' => '5FZ2Z8QIkA7UTZ4BYkoC+GsReLf569mSKDsfods6LYQ8t+a8EW9oaircfMpmaLbPBh4FOBiiFyLfuZmTSUwzZg==',
            'enabled' => true
        ),
    ];

    return new InMemoryUserProvider($users);
};
```

Add config for silex security

```
$app['security.firewalls'] = array(
    'login' => [
        'pattern' => 'login|register|oauth',
        'anonymous' => true,
    ],
    'secured' => array(
        'pattern' => '^.*$',
        'logout' => array('logout_path' => '/logout'),
        'users' => $app['users'],
        'jwt' => array(
            'use_forward' => true,
            'require_previous_session' => false,
            'stateless' => true,
        )
    ),
);
```

Register silex providers

```
$app->register(new Silex\Provider\SecurityServiceProvider());
$app->register(new Silex\Provider\SecurityJWTServiceProvider());
```

### Example for authorization and request for protected resources

[](#example-for-authorization-and-request-for-protected-resources)

```
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\User\InMemoryUserProvider;
use Symfony\Component\Security\Core\User\User;

$app->post('/api/login', function(Request $request) use ($app){
    $vars = json_decode($request->getContent(), true);

    try {
        if (empty($vars['_username']) || empty($vars['_password'])) {
            throw new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $vars['_username']));
        }

        /**
         * @var $user User
         */
        $user = $app['users']->loadUserByUsername($vars['_username']);

        if (! $app['security.encoder.digest']->isPasswordValid($user->getPassword(), $vars['_password'], '')) {
            throw new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $vars['_username']));
        } else {
            $response = [
                'success' => true,
                'token' => $app['security.jwt.encoder']->encode(['name' => $user->getUsername()]),
            ];
        }
    } catch (UsernameNotFoundException $e) {
        $response = [
            'success' => false,
            'error' => 'Invalid credentials',
        ];
    }

    return $app->json($response, ($response['success'] == true ? Response::HTTP_OK : Response::HTTP_BAD_REQUEST));
});

$app->get('/api/protected_resource', function() use ($app){
    return $app->json(['hello' => 'world']);
});

$app->run();
```

Full example in directory tests/mock/app.php

And should for tests correct work silex-security-jwt-provider

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity42

Moderate usage in the ecosystem

Community25

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 83.1% 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

Every ~36 days

Recently: every ~109 days

Total

22

Last Release

3379d ago

Major Versions

1.0 → 2.02015-06-19

1.0.3 → 2.0.42015-08-21

1.0.5 → 2.0.52015-11-27

1.0.6 → 2.1.02015-12-02

1.1.0 → 2.1.12017-02-09

### Community

Maintainers

![](https://www.gravatar.com/avatar/983877e47ff9f3f39106d5af83df982cb7d1042b9bf640ce96a35b139474d874?d=identicon)[cnam](/maintainers/cnam)

---

Top Contributors

[![cnam](https://avatars.githubusercontent.com/u/1832776?v=4)](https://github.com/cnam "cnam (54 commits)")[![gaving](https://avatars.githubusercontent.com/u/43741?v=4)](https://github.com/gaving "gaving (4 commits)")[![ronanguilloux](https://avatars.githubusercontent.com/u/313677?v=4)](https://github.com/ronanguilloux "ronanguilloux (3 commits)")[![monteiro](https://avatars.githubusercontent.com/u/74459?v=4)](https://github.com/monteiro "monteiro (2 commits)")[![royopa](https://avatars.githubusercontent.com/u/442991?v=4)](https://github.com/royopa "royopa (1 commits)")[![vladimirbasic](https://avatars.githubusercontent.com/u/3469953?v=4)](https://github.com/vladimirbasic "vladimirbasic (1 commits)")

---

Tags

phpsecurity-jwtsilexsilex-security

### Embed Badge

![Health badge](/badges/cnam-security-jwt-service-provider/health.svg)

```
[![Health](https://phpackages.com/badges/cnam-security-jwt-service-provider/health.svg)](https://phpackages.com/packages/cnam-security-jwt-service-provider)
```

###  Alternatives

[google/auth

Google Auth Library for PHP

1.4k272.7M162](/packages/google-auth)[thenetworg/oauth2-azure

Azure Active Directory OAuth 2.0 Client Provider for The PHP League OAuth2-Client

2509.6M48](/packages/thenetworg-oauth2-azure)[stevenmaguire/oauth2-keycloak

Keycloak OAuth 2.0 Client Provider for The PHP League OAuth2-Client

2275.9M27](/packages/stevenmaguire-oauth2-keycloak)[robsontenorio/laravel-keycloak-guard

🔑 Simple Keycloak Guard for Laravel

5161.1M3](/packages/robsontenorio-laravel-keycloak-guard)[patrickbussmann/oauth2-apple

Sign in with Apple OAuth 2.0 Client Provider for The PHP League OAuth2-Client

1132.5M6](/packages/patrickbussmann-oauth2-apple)[wp-graphql/wp-graphql-jwt-authentication

JWT Authentication for WPGraphQL

361118.4k1](/packages/wp-graphql-wp-graphql-jwt-authentication)

PHPackages © 2026

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