Developer forum

Forum » CMS - Standard features » External Login Provider (Azure + Azure B2C) can get user stuck in redirect to provider

External Login Provider (Azure + Azure B2C) can get user stuck in redirect to provider

Kevin Steffer
Kevin Steffer
Reply

Using the one of the Login Providers can cause users to end up in an redirect lock to the Login Provider.

If you for some reason can't login or by accident click on the external login provider link and you end up on the login.mocrosoft.com login screen - you can't get back to the website because it just continues to redirect you to the login provider.

Solution

Find a way to remove the cookies set by the login provider if you return back to the site without a login command.

Workaround

We have built a workaround for this using a custom version of the LoginProvider with this code

if (!this.IsSignedIn())
      {
        // Guard for infinite authentication loop where you can visit the website if you have the DW_ExtranetSessionCookie
        // We'll catch the reuest and remove the cookie and redirect you back to the website
        if (Context.Current.Request.HttpMethod == "GET" && !Context.Current.Request.Path.ToLower().Contains("/admin"))
        {
          string redirect = Context.Current.Request.Url.PathAndQuery;
          Context.Current.Response.Redirect("/AzureResetAuthentication.aspx?redirect="+ HttpUtility.UrlEncode(redirect));
        }

And in our AzureResetAuthentication.aspx we simply just expire the cookie

HttpCookie cookie = Request.Cookies["DW_ExtranetSessionCookie"];
if (cookie != null)
{
cookie.Value = string.Empty;
cookie.Expires = DateTime.Now.AddDays(-365);
cookie.SameSite = SameSiteMode.Lax;
Response.Cookies.Set(cookie);
}
 
And then we redirect the user to the URL they initially tried to request and without the cookie the user then doesn't get redirect to the login provider anymore.

Replies

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Kevin,

 

Thanks for sharing. We certainly fell into this in the past. Would be great to have it standard.

 

BR
Nuno

 
Oleg Rodionov Dynamicweb Employee
Oleg Rodionov
Reply

Hi,

it will be fixed by task #24431 on DW9 (fixed in DW10 by new implementation of external authentication).

BR, Oleg QA

 

 

You must be logged in to post in the forum