I added full path urls to login destination.
For a user with role_1 I want them to go to domain1.com/dashboard
And for users with role_2 i want them to to domain2.com/dashboard

Both domains are connected to the same drupal installation and are added as trusted host to site settings.
Doing this gives me the following error:

Redirects to external URLs are not allowed by default, use \Drupal\Core\Routing\TrustedRedirectResponse for it.

Comments

zebda created an issue. See original summary.

zebda’s picture

Issue summary: View changes
pradeepjha’s picture

Assigned: Unassigned » pradeepjha
pradeepjha’s picture

After applying attached patch, you will be able to redirect to different domain based on roles.

Steps to test:

1. For External URL:

  • Create two roles. Say role_1, role_2
  • Then add login destination rules based on roles.
  • Make sure it's redirecting correctly.

2. Repeat same steps for internal URL.

pradeepjha’s picture

Status: Active » Needs review
pradeepjha’s picture

Assigned: pradeepjha » Unassigned
nagarajan kumar’s picture

Status: Needs review » Reviewed & tested by the community

Hi,

I have tested this patch it is working for me.

rsvelko’s picture

Thanks for the patch!

I have a question:
- in the 2nd patch hunk in the function login_destination_perform_redirect() , we have:
---
179 if ($destination) {
180 // Check if it's a external URL.
181 if (UrlHelper::isExternal($destination->destination_path)) {
182 $response = new TrustedRedirectResponse($destination->destination_path);
183 $response->send();
184 }
185 $service->prepareDestination($destination);
---

... so the patch adds $response->send().

Then if the link is not external, we have $service->prepareDestination($destination);

My question, is it the right thing to call $response->send(); within login_destination_perform_redirect()
or is it better to call it from within prepareDestination() located in login_destination/src/LoginDestinationManager.php?
The added snippet of code in the hunk seems right , I wonder where is the right place to put that snipper?
I mean this snippet above - from line 181 to 184.

  • rsvelko committed 2874484 on 8.x-2.x authored by pradeepjha
    Issue #3097304 by pradeepjha: Use full path with different domain
    

  • rsvelko committed 20407e7 on 8.x-1.x authored by pradeepjha
    Issue #3097304 by pradeepjha: Use full path with different domain
    
rsvelko’s picture

Status: Reviewed & tested by the community » Fixed

In the end #4 looks good to me. Committing.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.