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

Fix Authenticator Class (getCredentials) example #7065

wants to merge 5 commits into from

Conversation

thtroyer
Copy link
Contributor

The current wording surrounding the getCredentials is misleading. Returning null does stop authentication, but it causes authentication to be successful. The example implies that X-AUTH-TOKEN is required and should be correct. For this behavior, either an AuthenticationException should be thrown or the credential variables should be initialized as empty and passed on to getUser().

The current wording surrounding the getCredentials is misleading.  Returning null does stop authentication, but it causes authentication to be successful.  The example implies that X-AUTH-TOKEN is required and should be correct.  For this behavior, either an AuthenticationException should be thrown or the credential variables should be initialized as empty and passed on to getUser().
< 8000 svg aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16" data-view-component="true" class="octicon octicon-tag color-fg-inherit">
// no token? Return null and no other methods will be called
return;
// No token? Cause authentication to fail.
throw new AuthenticationException();
Copy link
Member

Choose a reason for hiding this comment

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

What about setting $token to null then?

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.

I think throwing the exception in getCredentials is more explicit about the fact this authenticator will not allow any request not having this header (and won't let other authenticators try).

@thtroyer
Copy link
Contributor Author

Thanks for the feedback. I wasn't sure which solution would match Symfony's style better (exception vs empty variables) and had just picked one.

I've adjusted the solution and comments.

* 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 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.

@thtroyer
Copy link
Contributor Author
thtroyer commented Nov 9, 2016

Thanks for the feedback @ogizanagi . It didn't occur to me that multiple authenticators could be set up, but that makes sense.

return;
// No token?
// Throwing an exception will cause authentication
// to fail and prevent other authenticators from
Copy link
Member

Choose a reason for hiding this comment

The 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?

@xabbuh
Copy link
Member
xabbuh commented Nov 11, 2016

👍

Status: Reviewed

* 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
Copy link
Contributor

Choose a reason for hiding this comment

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

- * be passed to getUser().  Returning null will cause this authenticator
+ * be passed to getUser(). Returning null will cause this authenticator

// Throwing an exception will cause authentication
// to fail and prevent other authenticators from
// attempting to authenticate.
throw new AuthenticationException('No token provided.');
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

@HeahDude
Copy link
Contributor

Status: needs work

Copy link
Contributor
@HeahDude HeahDude left a comment

Choose a reason for hiding this comment

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

Thank you for improving this! 👍

Should be merged in 2.8.

@xabbuh
Copy link
Member
xabbuh commented May 17, 2017

Thank you @thtroyer.

xabbuh added a commit that referenced this pull request May 17, 2017
This PR was submitted for the 3.1 branch but it was merged into the 2.8 branch instead (closes #7065).

Discussion
----------

Fix Authenticator Class (getCredentials) example

The current wording surrounding the getCredentials is misleading.  Returning null does stop authentication, but it causes authentication to be successful.  The example implies that X-AUTH-TOKEN is required and should be correct.  For this behavior, either an AuthenticationException should be thrown or the credential variables should be initialized as empty and passed on to getUser().

Commits
-------

52d56f4 Fix Authenticator Class (getCredentials) example
@xabbuh xabbuh added this to the 2.8 milestone May 17, 2017
@xabbuh xabbuh closed this May 17, 2017
xabbuh added a commit that referenced this pull request May 18, 2017
This PR was merged into the 2.8 branch.

Discussion
----------

pass only strings to loadUserByUsername()

This completes #7065 as since the change made there the `token` key can refer to `null`.

Commits
-------

a47ed88 pass only strings to loadUserByUsername()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
0