-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsimple.php
More file actions
46 lines (36 loc) · 1.32 KB
/
simple.php
File metadata and controls
46 lines (36 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
require __DIR__.'/../vendor/autoload.php';
use Symfony\Component\HttpFoundation\Request;
$app = new Silex\Application();
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
$app['debug'] = true;
$app['env'] = 'dev';
$app->get('/', function (Request $request) use ($app) {
$output = 'Hello!';
if ($request->attributes->has('stack.authn.token')) {
$output .= ' Your token is '. $request->attributes->get('stack.authn.token');
} else {
$output .= ' <a href="'.$app['url_generator']->generate('login').'">Login</a>';
}
return $output;
})->bind('home');
$app->get('/login', function (Request $request) use ($app) {
return $app->redirect($app['url_generator']->generate('home'));
})->bind('login');
$app = (new Stack\Builder())
->push('Dflydev\Stack\BasicAuthentication', [
'firewall' => [
['path' => '/', 'anonymous' => true],
['path' => '/login'],
],
'authenticator' => function ($username, $password) {
if ('admin' === $username && 'default' === $password) {
return 'admin-user-token';
}
},
'realm' => 'here there be dragons',
])
->resolve($app);
$request = Request::createFromGlobals();
$response = $app->handle($request)->send();
$app->terminate($request, $response);