Skip to content

Commit

Permalink
Merge branch 'CoolGoose-patch-1'
Browse files Browse the repository at this point in the history
Closes #63
  • Loading branch information
akrabat committed Dec 6, 2016
2 parents ee7d491 + ef69e8a commit 9aa3d20
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ $container['csrf'] = function ($c) {
// If you are implementing per-route checks you must not add this
$app->add($container->get('csrf'));

$app->get('/foo', function ($req, $res, $args) {
$app->get('/foo', function ($request, $response, $args) {
// CSRF token name and value
$nameKey = $this->csrf->getTokenNameKey();
$valueKey = $this->csrf->getTokenValueKey();
$name = $req->getAttribute($nameKey);
$value = $req->getAttribute($valueKey);
$name = $request->getAttribute($nameKey);
$value = $request->getAttribute($valueKey);

// Render HTML form which POSTs to /bar with two hidden input fields for the
// name and value:
// <input type="hidden" name="<?= $nameKey ?>" value="<?= $name ?>">
// <input type="hidden" name="<?= $valueKey ?>" value="<?= $value ?>">
});

$app->post('/bar', function ($req, $res, $args) {
$app->post('/bar', function ($request, $response, $args) {
// CSRF protection successful if you reached
// this far.
});
Expand All @@ -75,11 +75,11 @@ $container['csrf'] = function ($c) {
return new \Slim\Csrf\Guard;
};

$app->get('/api/myEndPoint',function ($req, $res, $args) {
$app->get('/api/myEndPoint',function ($request, $response, $args) {
$nameKey = $this->csrf->getTokenNameKey();
$valueKey = $this->csrf->getTokenValueKey();
$name = $req->getAttribute($nameKey);
$value = $req->getAttribute($valueKey);
$name = $request->getAttribute($nameKey);
$value = $request->getAttribute($valueKey);

$tokenArray = [
$nameKey => $name,
Expand All @@ -89,7 +89,7 @@ $app->get('/api/myEndPoint',function ($req, $res, $args) {
return $response->write(json_encode($tokenArray));
})->add($container->get('csrf'));

$app->post('/api/myEndPoint',function ($req, $res, $args) {
$app->post('/api/myEndPoint',function ($request, $response, $args) {
//Do my Things Securely!
})->add($container->get('csrf'));

Expand Down

0 comments on commit 9aa3d20

Please sign in to comment.