question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Azure AD B2C - HTTP Error 400 - Request Header field is too long

See original GitHub issue

I am using Microsoft.Idendity.Client(V4.0.0) library along with Xamarin for login to Azure AD B2C account.

Previously I was using external browse(chrome) for opening the login window. And yesterday I changed the code like given below.

var result = await _authenticationClient.AcquireTokenInteractive(_settings.Scopes)
                    .WithParentActivityOrWindow(ParentActivityOrWindow)
                    .WithPrompt(Prompt.ForceLogin)
                    .WithUseEmbeddedWebView(true)
                    .ExecuteAsync();

I have changed the behavior to open the embedded browser for login by adding the .WithUseEmbeddedWebView(true) configuration.

After changing this, I am getting an error page(intermittently) saying that “Bad Request - Header Field too long”

HTTP Error 400 - Request Header field is too long.

Attaching the error image for your reference.

59831160-7e24a980-9341-11e9-91b0-f810d62763d7

Could you please let me know why this issue is coming and how I can resolve it. Do I need to consider for something else, in case if I am using EmbeddedWebView.

Also I have noticed that It is not coming every-time. Seems like something weird happen with my code.

Please help.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
rkshnaircommented, Sep 5, 2019

I have added the below code when the user try for re-login and everything works fine for me.

 public Task ClearCookiesAsync()
        {
            var context = Android.App.Application.Context;

            if (Build.VERSION.SdkInt >= BuildVersionCodes.LollipopMr1)
            {
                System.Diagnostics.Debug.WriteLine("Clearing cookies for API >= LollipopMr1");
                CookieManager.Instance.RemoveAllCookies(null);
                CookieManager.Instance.Flush();
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("Clearing cookies for API < LollipopMr1");
#pragma warning disable CS0618 // Type or member is obsolete
                var cookieSyncMngr = CookieSyncManager.CreateInstance(context);
#pragma warning restore CS0618 // Type or member is obsolete
                cookieSyncMngr.StartSync();
                var cookieManager = CookieManager.Instance;
                cookieManager.RemoveAllCookie();
                cookieManager.RemoveSessionCookie();
                cookieSyncMngr.StopSync();
                cookieSyncMngr.Sync();
            }

            return Task.FromResult(true);
        }
0reactions
bgavrilMScommented, Sep 5, 2019

Thanks for following up @rkshnair !

Read more comments on GitHub >

github_iconTop Results From Across the Web

Azure Portal: Bad Request - Request Too Long
The error HTTP 400: Size of header request is too long generally happens because there's too many cookies or cookies that are too...
Read more >
HTTP Error 400. The size of the request headers is too long.
This error generally occurs when there's too many cookies or cookies that are too big. Each time you are signing in, it's storing...
Read more >
Bad Request - Request Too Long · Issue #10
Upon signing into my tenant I'm receiving: Bad Request - Request Too Long HTTP Error 400. The size of the request headers is...
Read more >
"The size of the request headers is too long" error when ...
Bad Request - Request Too Long HTTP Error: 400: The size of the request headers is too long. Solutions For Any Environment. Decrease...
Read more >
Azure AD B2C: Bad Request - Request Too Long HTTP Error ...
Coding example for the question Azure AD B2C: Bad Request - Request Too Long HTTP Error 400. The size of the request headers...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found