Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite4f5c6e

Browse files
Sam HudsonSam Hudson
Sam Hudson
authored and
Sam Hudson
committed
added information on AuthenticationFailureHandlerInterface in api keys docs
1 parent0a65b6f commite4f5c6e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

‎cookbook/security/api_key_authentication.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,27 @@ exception in ``refreshUser()``.
210210
If you *do* want to store authentication data in the session so that
211211
the key doesn't need to be sent on every request, see:ref:`cookbook-security-api-key-session`.
212212

213+
Handling Exceptions
214+
-------------------
215+
216+
In order for you're ``ApiKeyAuthentication`` to correctly display a 403 http status when either bad credentials, or authentication fails you will need to implement the ``AuthenticationFailureHandlerInterface`` on your Authenticator. This will provide a method ``onAuthenticationFailure`` which you can then return a ``Response`` with.
217+
218+
// src/Acme/HelloBundle/Security/ApiKeyAuthenticator.php
219+
namespace Acme\HelloBundle\Security;
220+
221+
use Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface;
222+
use Symfony\Component\HttpFoundation\Response;
223+
224+
class ApiKeyAuthenticator implements SimplePreAuthenticatorInterface, AuthenticationFailureHandlerInterface
225+
{
226+
//...
227+
228+
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
229+
{
230+
return new Response("Authentication Failed.", 403);
231+
}
232+
}
233+
213234
.. _cookbook-security-api-key-config:
214235

215236
Configuration

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp