-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Fix Authenticator Class (getCredentials) example #7065
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
234d537
a5832a2
df4266e
90de243
ebb8153
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,14 +164,18 @@ This requires you to implement six methods:: | |
class TokenAuthenticator extends AbstractGuardAuthenticator | ||
{ | ||
/** | ||
* Called on every request. Return whatever credentials you want, | ||
* or null to stop authentication. | ||
* Called on every request. Return whatever credentials you want to | ||
* be passed to getUser(). Returning null will cause this authenticator | ||
* to be skipped. | ||
*/ | ||
public function getCredentials(Request $request) | ||
{ | ||
if (!$token = $request->headers->get('X-AUTH-TOKEN')) { | ||
// no token? Return null and no other methods will be called | ||
return; | ||
// No token? | ||
// Throwing an exception will cause authentication | ||
// to fail and prevent other authenticators from | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please reduce the number of spaces here so that all comments are aligned? |
||
// attempting to authenticate. | ||
throw new AuthenticationException('No token provided.'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a bad implementation, because it prevents any other auth system to be used (including the anonymous auth). We should not advocate it. The Symfony security system is precisely meant to allow multiple auth strategies in parallel. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, this should be reverted and added in a note or caution block. |
||
} | ||
|
||
// What you return here will be passed to getUser() as $credentials | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.