How can I redirect .NET core 3.1 Open ID Connect to public url after successful auth?

Viewed 39

I have a .NET Core 3.1 Blazor app which uses AddOpenIdConnect (https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.dependencyinjection.openidconnectextensions.addopenidconnect?view=aspnetcore-3.1)

All works well locally when I setup the options for the ID Server authority etc.

The problem is when in the development environment the app runs on mysite.local and is publicly available on mysite.public so when the auth happens via ID Server the redirect is to https://mysite.local/signin-oidc not https://mysite.public/signin-oidc

No matter what I do this will not redirect back to the public url. I've tried

services.AddOpenIdConnect("oicd", options => {
   ...
   options.CallbackPath = "https://mysite.public/signin-oidc"; // exception - path must start with '/'
   options.CallbackPath = "/signin-oidc"; // redirects to https://mysite.local/signin-oidc
   ...
})

and also set the redirecturi in the login page:

public class LoginModel: PageModel
{
   public async Task OnGet(string redirectUri)
   {
      await HttpContext.ChallengeAsync("oidc",
         new AuthenticationProperties 
         {
            RedirectUri = redirectUri
         })
   }
}

with

<a href="login?redirectUri=https://mysite.public/original-page">Log in</a>

Any ideas gratefully received, is there some way to set the base uri maybe?

0 Answers
Related