8000 Fix Authenticator Class (getCredentials) example by thtroyer · Pull Request #7065 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

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

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Authenticator class example - adjusting solution.
  • Loading branch information
thtroyer committed Oct 31, 2016
commit a5832a2f7a8b5ae12c43242fe5b1b7d866647440
11 changes: 5 additions & 6 deletions security/guard_authentication.rst
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,15 @@ This requires you to implement six methods::
class TokenAuthenticator extends AbstractGuardAuthenticator
{
/**
* Called on every request. Return whatever credentials you want, which
* will be passed to getUser(). Returning null skips all other authentication
* steps. Throwing an AuthenticationException will cause authentication to fail,
* calling onAuthenticationFailure().
* Called on every request. Return whatever credentials you want to
* be passed to getUser(). Returning null will cause authentication
Copy link
Contributor
@ogizanagi ogizanagi Oct 31, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'll not necessary cause the authentication to be successful, given that you can have multiple guard authenticators. It only means this authenticator was unable to extract credentials from the request, and thus will give hand to the next ones.

* to be successful, skipping the rest of the authentication process.
*/
public function getCredentials(Request $request)
{
if (!$token = $request->headers->get('X-AUTH-TOKEN')) {
// No token? Cause authentication to fail.
throw new AuthenticationException();
// No token?
$token = null;
}

// What you return here will be passed to getUser() as $credentia 4145 ls
Expand Down
0