HttpListenerRequest.HasEntityBody is False value for unknown reason

84 Views Asked by At

I've being trying to implement OAuth 2.0 with google on a web application. But for some reason, Request.HasEntityBody property is null.

On the Oauth server, I get the response with Status Code 200 with the valid data but no progress on login phase.

Steps I'm doing are:

  1. booting app
  2. login with google.
  3. browser tab opens with https://accounts.google.com/o/oauth2/auth.
  4. login closes tab and open the app on login menu instead of logging in.

Any tips on how to solve this case? Thanks in advance.

public async Task<int> ListenCallback(string requestURL, string defaultBrowserName)
{
    int statusCode = 0;

    try
    {
        HttpListenerContext ctx = await listener.GetContextAsync();
        // ctx.Request.HasEntityBody = Null

        HttpListenerRequest req = ctx.Request;
        HttpListenerResponse resp = ctx.Response;

        resp.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With");
        resp.AddHeader("Access-Control-Allow-Methods", "GET, POST");
        resp.AddHeader("Access-Control-Allow-Headers", "*");
        resp.AppendHeader("Access-Control-Allow-Origin", "*");
        resp.ContentType = "text/plain;charset=UTF-8";

        string jsonString = new StreamReader(req.InputStream).ReadToEnd();

        if (!string.IsNullOrEmpty(jsonString))
        {
            statusCode = WriteResponseToCache(jsonString: jsonString, responseURL: requestURL, isRefresh: false);
        }

        resp.Close();
        listener.Close();
        CloseOauthTab(defaultBrowserName);

        return statusCode;
    }
    catch (Exception ex)
    {
        listener.Stop();
        listener.Close();
        CloseOauthTab(defaultBrowserName);
        
        if (!IsFailover)
        {
            if ((ex is TimeoutException) ||
               ((ex is WebException) &&
                (ex as WebException).Status == WebExceptionStatus.Timeout))
            {
                IsFailover = true;
                return await OauthLoginRequest();
            }
        }

            return statusCode;
    }
}
0

There are 0 best solutions below