Skip to content

linkorb/flex-auth-provider

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 

Repository files navigation

flex-auth-provider

FlexAuth: Silex provider

FlexAuthProvider provider integration FlexAuth library to Silex framework.

Using

use Silex\Application;

$app = new Application();

//....

$app->register(new \Silex\Provider\SessionServiceProvider());
$app->register(new \FlexAuthProvider\FlexAuthProvider());

// define login page for redirect if jwt authentication is failed via browser 
$app['flex_auth.jwt.redirect_login_page'] = "/login";

$app['security.user_provider.main'] = function ($app) {
    return $app['flex_auth.security.user_provider'];
};

$app->register(new Silex\Provider\SecurityServiceProvider(), [
    'security.firewalls' => [
        'main' => [
            # https://silex.symfony.com/doc/2.0/cookbook/guard_authentication.html
            'guard' => [
                'authenticators' => [
                    'flex_auth.type.jwt.security.authenticator'
                ],
            ],
            'form' => [
                'login_path' => '/login',
                'default_target_path' => '/',
                'check_path' => '/login_check'
            ],
            'logout' => [
                'logout_path' => '/logout',
                'target_url' => 'homepage',
                'invalidate_session' => true
            ],
            'anonymous' => true,
        ],
    ],
]);
$app['security.default_encoder'] = function ($app) {
    return $pimple['flex_auth.security.password_encoder'];
    // return new \Symfony\Component\Security\Core\Encoder\PlaintextPasswordEncoder();
};

Links

Silex demo

The Security Component(Symfony Docs)