As of new 2.x-dev social_auth has a feature to redirect user back to destination page on successful authentication. It should also have an error destination page. So, if any error occurs on login we can redirect back user to the origin page and not the `user.login` route.
A valid scenario here is:
During checkout process, we can have a login block as a checkout step. So this is a login panel inside checkout not the user login / register page. But a block which allows user to get login and continue the process.
So, When user tries social authentication and fails it should return back to checkout login page not the user login page.
Comments
Comment #2
miteshmapComment #3
miteshmapComment #4
miteshmapComment #5
miteshmapComment #6
gvsoThis looks like a valid thing to add. However, I wonder if this problem could not be solved by using events instead.
If we are to include something like this, we might want to allow options to redirect to the origin in successful or failed logins. Something that is more general. What do you think about allowing this to be the case?
Comment #7
gvsoBy the way, we might want to include these as options in the settings form then
Comment #8
miteshmap@gvso IMHO, This part is already covered in current social_auth module, the social auth link supports "destination" query string param. So, if we pass the destination in social auth link, It redirects back to that path on successful login.
But that is not mentioned anywhere. Neither in settings or in README file. I think we need to cover that part.
So, the only thing that we need to do is, to add settings to allow user to redirect back to origin page when destination is used. What do you think about this?
Comment #9
gvsoSorry, I think I'm not getting your point correctly.
Are you saying that we need to provide a way to allow the destination parameter to be set to the origin?
For instance, the user is at /node/5 and tries to log in. Then, the
destinationwould be set to /node/5Comment #10
miteshmapThere are two things here:
Destination link is the next page after login, and error destination is the original page from where the login request is being made.
Sorry! I again considering a scenario of checkout process (And ignoring user login/register as it's working fine and no change needed there.):
/checkout/login?destination=/checkout/paymentuser/login/facebook?destination=/checkout/paymentHTTP_REFERER, and set it in session withlogin_error_destinationkey.user/login/facebookpath we store the HTTP_REFERER which is /checkout/login aslogin_error_destination.so, when user authenticated successfully we redirect them to
login_destinationelse on error redirect them tologin_error_destinationComment #11
gvsoTwo things here:
dispatchAuthenticationErrormethod in Social Auth and call it in these cases. This will give the developer more flexibility in determining what exactly to do in a failed login.ogin_destinationandlogin_error_destination. I would like things to be as simple as possible in the implementer's side.Comment #12
miteshmapComment #13
gvsoI'm concerned that this will break everything. We need backward compatibility as we did with
$renderer.Maybe ProviderRedirectEvent. Let's try to get rid of the SocialAuth prefix in most of our classes.
Do we need this? I wonder if the event listener can't just do the redirection if there's an error in provider.
Comment #14
gvsoAnother way to go about might be to use
userAuthenticatorto handle the error dispatching. This object already contains the event dispatcherComment #15
miteshmapThe class has the object protected, it will require a public helper method to use it outside the class.
Instead, I think we should inject the dependency inside OAuth2ControllerBase itself as optional, and if not passed, we'll use the service like the
$renderer.From, Comment #13 - third point.
No we don't need that.
I'll remove all unnecessary methods from SocialAuthProviderEvent (ProviderRedirectEvent) and SocialAuthProviderErrorEvent (ProviderErrorEvent).
Comment #16
miteshmapComment #17
miteshmapComment #18
gvsoThanks!
Why can't this code be in UserAuthenticator? Injecting the event dispatcher service is a pain for two reasons. First, we'll need to update all implementers. Second, I think it feels more natural to just have it in UserAuthenticator since it is an error with authentication.
Of course, doing so wouldn't allow us to dispatch an event before redirecting, but I'm not sure why you would need one. Any thoughts?
The other option is to have a
getEventDispatcherinUserAuthenticator, so we can dispatch an event before redirecting without injecting the service.Comment #19
miteshmapOnly reason to do this is, to use "destination" from request. https://git.drupalcode.org/project/social_auth/blob/8.x-2.x/src/Controller/OAuth2ControllerBase.php#L182
Updating that too, creating
dispatchBeforeRedirecthelper method insideUserAuthenticator. we will use that here in-place of,Comment #20
miteshmapComment #21
gvsoWould you mind sharing an interdiff? Also, some documentation would be nice for this issue. We can create a new doc page for 'Handling authentication errors' or something similar, like this page.
Comment #22
miteshmapHere is the interdiff, Do you want me to add the documentation here? OR I can add details in discussion at - https://www.drupal.org/node/2971213/discuss
Comment #23
gvsoPlease add a new documentation page under the Social Auth documentation guide. This will also help me test the changes and we'll have documentation for this. Even if we decide to change some parts of your patch, I believe the new events would work anyways.
Thank you for working on this! I would love to include it in the next release
Comment #24
gvsoComment #26
gvsoI made a few changes regarding the events' names and constants. I also updated the documention and will add the example in social_api_examples.
Thank you so much! This was an awesome job!
Comment #27
miteshmapNice job on naming correction and document. Thank you so much @gvso for accepting this feature request on priority.