Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect client app (instead of using initially requested url) after a successful login?

I have an asp.net core application with OpenID Connect authentication all working properly. The thing is, I want to redirect the client after a successful login, instead of using the callback url that is embedded in the state property in the querystring. How do I do that from the Client/Startup.cs?

In the code example below, say the user bookmarked or type in /home/Second, and after a successful login, I want to always redirect to /home/Index. How do I do this?

    [Authorize]
    public class HomeController : Controller 
    { 
         public async Task<IActionResult> Index()
         {
            return View(); 
         }

         public async Task<IActionResult> Second()
         {
            return View(); 
         }
    }
like image 655
Joe Avatar asked Sep 13 '25 12:09

Joe


1 Answers

You need something like:

services.AddAuthentication().AddOpenIdConnect(options =>
            {
                options.Events = new OpenIdConnectEvents
                {
                    OnTicketReceived = ctx =>
                    {
                        // can be First, Second, Index, whatever
                        ctx.ReturnUri = "http://google.com"; 
                        return Task.CompletedTask;
                    }
                }
            }
like image 152
d_f Avatar answered Sep 16 '25 09:09

d_f



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!