Skip to content

Commit 9d84809

Browse files
committed
Merge pull request symfony#2614 from FlyersWeb/improving_custom_authentication_provider
Improved code of custom authentication provider cookbook article
2 parents c972162 + 20a6775 commit 9d84809

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

cookbook/security/custom_authentication_provider.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,9 @@ set an authenticated token in the security context if successful.
137137
138138
try {
139139
$authToken = $this->authenticationManager->authenticate($token);
140-
141140
$this->securityContext->setToken($authToken);
141+
142+
return;
142143
} catch (AuthenticationException $failed) {
143144
// ... you might log something here
144145
@@ -152,6 +153,11 @@ set an authenticated token in the security context if successful.
152153
$event->setResponse($response);
153154
154155
}
156+
157+
// By default deny authorization
158+
$response = new Response();
159+
$response->setStatusCode(403);
160+
$event->setResponse($response);
155161
}
156162
}
157163
@@ -233,6 +239,10 @@ the ``PasswordDigest`` header value matches with the user's password.
233239
if (file_exists($this->cacheDir.'/'.$nonce) && file_get_contents($this->cacheDir.'/'.$nonce) + 300 > time()) {
234240
throw new NonceExpiredException('Previously used nonce detected');
235241
}
242+
// If cache directory does not exist we create it
243+
if (!is_dir($this->cacheDir)) {
244+
mkdir($this->cacheDir, 0777, true);
245+
}
236246
file_put_contents($this->cacheDir.'/'.$nonce, time());
237247
238248
// Validate Secret

0 commit comments

Comments
 (0)