linkorb / silex-provider-jwt-auth
Provides a jwt_issuer firewall and JWT decoder.
Installs: 60
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 2
Open Issues: 0
pkg:composer/linkorb/silex-provider-jwt-auth
Requires
- firebase/php-jwt: ^5.0
- pimple/pimple: ^3.0
- silex/silex: ^2.0
- symfony/security: ^2.8 || ^3.0 || ^4.0
README
Provides a firewall which uses, as its authentication provider, an issuer of Json Web Tokens.
Install
Install using composer:-
$ composer require linkorb/silex-provider-jwt-auth
Note: use the v1 branch when you're restricted to using version 2.7.x of symfony/security.
Then configure and register the provider along with the Silex Session and Security providers:-
// app/app.php
use LinkORB\JwtAuth\Provider\JwtAuthenticatorServiceProvider;
use Silex\Provider\SecurityServiceProvider;
use Silex\Provider\SessionServiceProvider;
...
$app->register(new SessionServiceProvider);
$app->register(
    new SecurityServiceProvider,
    [
        'security.firewalls' => [
            'my_firewall' => [
                'pattern' => '^/secure-area',
                'stateless' => false,
                'jwt_issuer' => [
                    'app_identifier' => 'my-app-name',
                    'jwt_issuer_url' => 'https://example.com/issue/a/jwt',
                    // see JwtAuthenticatorServiceProvider for more options
                ],
                'users' => function () use ($app) {
                    return $app['my_user_provider'];
                },
            ],
        ],
    ]
);
$app->register(
    new JwtAuthenticatorServiceProvider,
    [
        'jwt_auth.decoder.config' => [
            'decoder_key' => function () {
                return file_get_contents('/path/to/jwt/decoder/key.pub');
            },
            'permitted_algos' => ['RS256', 'RS384', 'RS512'],
        ],
    ]
);