PHP code example of linkorb / flex-auth-provider

1. Go to this page and download the library: Download linkorb/flex-auth-provider library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

linkorb / flex-auth-provider example snippets


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();
};