4

Given

A ASP MVC website in IIS. The site authenticated the users with an identityserver with an impicit flow.

There are mutiple domains assiged to it. So the website is called from different domains.

for example.

  • foo.com
  • foo.de
  • foo.fr

Problem

Now when I configure my website I have to set the redirect url but it depends on where the user comes from. But as this configuration is done when the application starts i couldn't make a difference depending on the incoming request.

What is the recommended approach for this?

 public static void Configure(IAppBuilder app)
 {
      app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
            {
                AuthenticationType = "oidc",
                Authority = ConfigurationManager.AppSettings["authority"],
                ClientId = "BlsFrontend",
                RedirectUri = "http://foo.de", //how to get this dynamically?
                ResponseType = "id_token token",
                SignInAsAuthenticationType = "Cookies",
                Scope = "openid profile",

One thing i'm thinking of is to use the RedirectToIdentityProvider Notification and adpot the redirect in the request. I tested it and it works in my case, but would this be a valid/good approach?

RedirectToIdentityProvider = n =>
{
    if (!string.IsNullOrWhiteSpace(n.ProtocolMessage.RedirectUri))
    {
        n.ProtocolMessage.RedirectUri = n.Request.Scheme + "://" + n.Request.Host.ToString(); //How to make it clean !?
    }
}
Boas Enkler
  • 12,264
  • 16
  • 69
  • 143

1 Answers1

0

I post this as the solution as I didn't find anything other to solve the problem and some others also used this solution

The solution is to set the redirect url depending on the request right before we are redirected to the identity server. For this I use the RedirectToIdentityProvider notification

RedirectToIdentityProvider = n =>
{

    if (n.ProtocolMessage.RequestType == OpenIdConnectRequestType.Authentication && 
        !string.IsNullOrWhiteSpace(n.ProtocolMessage.RedirectUri))
    {
        n.ProtocolMessage.RedirectUri = n.Request.Scheme + "://" + n.Request.Host.ToString(); //How to make it clean !?
    }
}
John Korsnes
  • 2,277
  • 2
  • 20
  • 31
Boas Enkler
  • 12,264
  • 16
  • 69
  • 143