PHPackages                             thcolin/silex-simpleuser-jwt - 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. thcolin/silex-simpleuser-jwt

AbandonedArchivedLibrary

thcolin/silex-simpleuser-jwt
============================

513PHP

Since Apr 29Pushed 10y agoCompare

[ Source](https://github.com/thcolin/silex-simpleuser-jwt)[ Packagist](https://packagist.org/packages/thcolin/silex-simpleuser-jwt)[ RSS](/packages/thcolin-silex-simpleuser-jwt/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Simple User (JWT) Provider for Silex
====================================

[](#simple-user-jwt-provider-for-silex)

An implementation of [jasongrimes/silex-simpleuser](https://github.com/jasongrimes/silex-simpleuser) with [JSON Web Token (JWT)](http://jwt.io/) frequently used in javascript frontend framework (AngularJS, ...)

Methods
-------

[](#methods)

- register
- login
- invite
- friends (list of your invits)
- forget (password)
- reset (password)
- update

Config
------

[](#config)

Check `tests/UserControllerTests.php` for full exemple (db, jwt, mailer, twig...)

```
use Silex\Application;
use SimpleUser\JWT\UserProvider;

$app = new Application();

// Useful to catch error and send them directly in JSON
$app -> error(function(Exception $e, $code) use($app){
  return $app -> json(['error' => $e -> getMessage(), 'type' => get_class($e)], $code);
});

// Default options
$app['user.jwt.options'] = [
  'language' => 'SimpleUser\JWT\Languages\English', // This class contains messages constants, you can create your own with the same structure
  'controller' => 'SimpleUser\JWT\UserController', // User controller, you can rewrite it
  'class' => 'SimpleUser\JWT\User', // If you want your own class, extends 'SimpleUser\JWT\User'
  'registrations' => [
    'enabled' => true,
    'confirm' => false // Send a mail to the user before enable it
  ],
  'invite' => [
    'enabled' => false // Allow user to send invitations
  ],
  'forget' => [
    'enabled' => false // Enable the 'forget password' function
  ],
  'tables' => [ // SQL tables
    'users' => 'users',
    'customfields' => 'user_custom_fields'
  ],
  'mailer' => [
    'enabled' => false,
    'from' => [
      'email' => 'do-not-reply@'.(isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST']:gethostname()),
      'name' => null
    ],
    // Email templates
    'templates' => [
      'register' => [
        'confirm' => 'confirm.twig',
        'welcome' => 'welcome.twig'
      ],
      'invite' => 'invite.twig',
      'forget' => 'forget.twig'
    ],
    // Routes name for email templates generation (optional if you don't want to use url in your email)
    'routes' => [
      'login' => 'user.jwt.login',
      'reset' => 'user.jwt.reset'
    ]
  ]
];

$app -> register(new UserProvider());
```

Routes
------

[](#routes)

There is a `Controller` in the library :

```
$app -> mount('/', new UserProvider());
```

- `POST` `/register` `{email, password}` : Register with email and password
- `POST` `/login` `{email, password}` : Return the JWT of the user
- `POST` `/invite` `{email}` : Email of your friend
- `GET` `/friends` : Return the list of friends
- `POST` `/forget` `{email}` : Email of the user who forget his password
- `POST` `/reset/{token}` `{password}` : Token sent by email, new password
- `POST` `/profil/{id}` `{email, password, name, username, customFields}` : All the postfields are optional

Client side
-----------

[](#client-side)

When you send request to your application, add HTTP header `X-Access-Token` with the token. On server side, in your Controller you can access to the `$user` like this :

```
$user = $app['security'] -> getToken() -> getUser();
```

Dependencies
------------

[](#dependencies)

### Database

[](#database)

Exemple with a SQLite database

```
use Silex\Provider\DoctrineServiceProvider;

$app -> register(new DoctrineServiceProvider(), [
  'db.options' => [
    'driver' => 'pdo_sqlite',
    'path' => __DIR__.'/app.db',
    'charset' => 'UTF8'
  ]
]);
```

### JWT

[](#jwt)

```
use Silex\Provider\SecurityServiceProvider;
use Silex\Provider\SecurityJWTServiceProvider;

$app['security.jwt'] = [
  'secret_key' => 'YOUR_OWN_SECRET_KEY',
  'life_time' => 2592000,
  'algorithm' => ['HS256'],
  'options' => [
    'header_name' => 'X-Access-Token',
    'username_claim' => 'email' // Needed for silex-simpleuser-jwt
  ]
];

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

### Mailer

[](#mailer)

Needed only if you want to use `confirm`, `reset` or `invite` functions

```
use Silex\Provider\SwiftmailerServiceProvider;

$app -> register(new SwiftmailerServiceProvider(), [
  'swiftmailer.options' => [
    'host' => '127.0.0.1',
    'port' => '25'
  ]
]);
```

### Twig

[](#twig)

Needed only if you want to use `confirm`, `reset` or `invite` functions (generate email templates)

```
use Silex\Provider\UrlGeneratorServiceProvider;
use Silex\Provider\TwigServiceProvider;

$app -> register(new TwigServiceProvider(), [
  'twig.path' => __DIR__.'/views'
]);

$app -> register(new UrlGeneratorServiceProvider());
```

Roles
-----

[](#roles)

```
/**
 * All this Roles are hardcoded in the library
 * ROLE_REGISTERED : Added to registered users
 * ROLE_INVITED : Added to invited users
 * ROLE_ALLOW_INVITE : Allow the user to invite friends
 * ROLE_ADMIN : Allow the user to update others users informations
 */

$app['security.role_hierarchy'] = [
  'ROLE_INVITED' => ['ROLE_USER'],
  'ROLE_REGISTERED' => ['ROLE_INVITED', 'ROLE_ALLOW_INVITE'],
  'ROLE_ADMIN' => ['ROLE_REGISTERED']
];
```

Firewalls
---------

[](#firewalls)

The firewalls are optional but, it's always good to secure your application

```
$app['security.firewalls'] = [
  'login' => [
    'pattern' => 'register|login|forget|reset',
    'anonymous' => true
  ],
  'secured' => [
    'pattern' => '.*$',
    'users' => $app['user.manager'], // Array with the all the users
    'jwt' => [
			'use_forward' => true,
			'require_previous_session' => false,
			'stateless' => true
    ]
  ]
];
```

Tests
-----

[](#tests)

There are unit tests in `tests/`, you can launch them with `phpunit`. You need to launch [MailCatcher](https://mailcatcher.me/) before making tests.

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

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

---

Top Contributors

[![thcolin](https://avatars.githubusercontent.com/u/9131757?v=4)](https://github.com/thcolin "thcolin (6 commits)")

### Embed Badge

![Health badge](/badges/thcolin-silex-simpleuser-jwt/health.svg)

```
[![Health](https://phpackages.com/badges/thcolin-silex-simpleuser-jwt/health.svg)](https://phpackages.com/packages/thcolin-silex-simpleuser-jwt)
```

PHPackages © 2026

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