PHPackages                             grimzy/security-json-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. grimzy/security-json-service-provider

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

grimzy/security-json-service-provider
=====================================

Service Provider JSON auth

v1.0.0(9y ago)021MITPHP

Since Feb 21Pushed 9y ago1 watchersCompare

[ Source](https://github.com/grimzy/security-json-service-provider)[ Packagist](https://packagist.org/packages/grimzy/security-json-service-provider)[ RSS](/packages/grimzy-security-json-service-provider/feed)WikiDiscussions master Synced 3w ago

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

Silex Security JSON Service Provider
====================================

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

[![Build Status](https://camo.githubusercontent.com/8b9f3497db908743c4aa76c6f8811af214aa2e57cb4854d09d6f3e38c8b15bc7/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f415243414e454445562f4c6f675669657765722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/grimzy/security-json-service-provider)[![Packagist](https://camo.githubusercontent.com/9939481cf3ac166d8e59895d667f1e0feeaf6f5b2ab911325b584cbfb67c5c58/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6772696d7a792f73656375726974792d6a736f6e2d736572766963652d70726f76696465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/grimzy/security-json-service-provider)[![Packagist](https://camo.githubusercontent.com/cd8dbafdc6e90cd89ca1ceb723e346bcb2945c2947f97e334fc9da290b2852c1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6772696d7a792f73656375726974792d6a736f6e2d736572766963652d70726f76696465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/grimzy/security-json-service-provider)[![Packagist Pre Release](https://camo.githubusercontent.com/94b4af4778076e377356d168976cca69a9c47efc595e2de95387efd77be3902b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f767072652f6772696d7a792f73656375726974792d6a736f6e2d736572766963652d70726f76696465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/grimzy/security-json-service-provider)[![license](https://camo.githubusercontent.com/7123c32787e013be5a8a13598ad01f562754637ed6141e89b02e85bf16d3e63e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6d6173686170652f6170697374617475732e7376673f7374796c653d666c61742d737175617265)](LICENSE)

This Security factory provides a cookie-less replacement for `form_login` which cannot be used .

Since they rely on cookies, the `switch_user` and `logout` config options are not supported with this Security factory.

**Security advisory:** Although you are not forced to, it is highly advised to use HTTPS.

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

[](#installation)

Using command line:

```
composer require grimzy/security-json-service-provider:1.0^
```

Or adding to composer.json:

```
"grimzy/security-json-service-provider:1.0^"

```

Usage
-----

[](#usage)

Configure firewalls:

```
$app['security.firewalls'] = [
  'login' => [
    'pattern' => '^/api/login',
    'anonymous' => true,
    'stateless' => true,
    'json' => [
      // Default configuration
      'username_parameter' => 'username',
      'password_parameter' => 'password',
      'post_only' => true,
      'json_only' => true
    ]
  ],

  'secured' => [
    'pattern' => '^.*$',
    'stateless' => true,
    'token' => true
  ],
];
```

Add a users provider:

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

Example configuration:

```
$app['security.firewalls' => [
  'login' => [
    'pattern' => '^/api/login',
    'anonymous' => true,
    'stateless' => true,
    'json' => [
      // Default configuration
      'username_parameter' => 'username',
      'password_parameter' => 'password',
      'post_only' => true,
      'json_only' => true
    ]
  ],

  'secured' => [
    'pattern' => '^.*$',
    'stateless' => true,
    'token' => true
  ],
]];
```

Register the service providers:

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

Define a route (**only accessible after successful authentication**):

```
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;

$app->post('/api/login', function(Request $request) use ($app) {
  $user = $app['user'];	// Logged in user

  $token = $app['some.token_encoder']->encode($user);

  return new JsonResponse([
    'token' => $token
  ]);
};
```

**Note:** if `post_only` is `false`, you can use `$app->get()` instead of `$app->post` when defining your route.

Override entry point
--------------------

[](#override-entry-point)

Create a new class implementing `Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface`:

```
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;

class GandalfAuthenticationEntryPoint implements AuthenticationEntryPointInterface
{
    /**
     * {@inheritdoc}
     */
    public function start(Request $request, AuthenticationException $authException = null)
    {
        return new Response('You shall not pass!', Response::HTTP_UNAUTHORIZED);
    }
}
```

Replace the packaged JsonAuthenticationEntrypoint with the created one:

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

// after registering the provider
$app['security.entry_point.json'] = function () use ($app) {
    return new GandalfAuthenticationEntryPoint();
};
```

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

Established project with proven stability

 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

3412d ago

### Community

Maintainers

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

---

Top Contributors

[![grimzy](https://avatars.githubusercontent.com/u/1837678?v=4)](https://github.com/grimzy "grimzy (16 commits)")

---

Tags

authenticationphpsilexsilex-security

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[jasongrimes/silex-simpleuser

A simple database-backed user provider for Silex, with associated services and controllers.

16817.0k2](/packages/jasongrimes-silex-simpleuser)[cnam/security-jwt-service-provider

Service Provider for usage jwt token for auth

60108.1k2](/packages/cnam-security-jwt-service-provider)[davec49/silex2-simpleuser

A simple database-backed user provider for Silex 2.0, with associated services and controllers forked from jasongrimes/SimpleUser.

131.1k](/packages/davec49-silex2-simpleuser)

PHPackages © 2026

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