Skip to content

Commit

Permalink
attempt at getting domain v3
Browse files Browse the repository at this point in the history
  • Loading branch information
NielsPilgaard committed Feb 24, 2024
1 parent 2cdc6c0 commit f7de910
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions src/web/Jordnaer/SignalR/AuthenticatedSignalRClientBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,35 @@ public async Task StopAsync(CancellationToken cancellationToken = default)
return null;
}

if (serverUri.Contains("[::]"))
if (!serverUri.Contains("[::]"))
{
_logger.LogInformation(
"First server address was {ServerUri}, trying to get hostname from environment variable 'WEBSITE_HOSTNAME' instead.", serverUri);
var cookieContainer = new CookieContainer(1);
cookieContainer.Add(new Cookie(
name: AuthenticationConstants.CookieName,
value: cookie,
path: "/",
domain: new Uri(serverUri).Host));
return cookieContainer;
}

serverUri = Environment.GetEnvironmentVariable("WEBSITE_HOSTNAME");
}
_logger.LogInformation(
"First server address was {ServerUri}, trying to get hostname from environment variable 'WEBSITE_HOSTNAME' instead.", serverUri);

if (serverUri is null)
var domain = Environment.GetEnvironmentVariable("WEBSITE_HOSTNAME");
if (domain is null)
{
_logger.LogError("Cannot determine domain for Cookie, Environment.GetEnvironmentVariable(\"WEBSITE_HOSTNAME\") was null.");
_logger.LogError("Cannot determine domain for Cookie, " +
"environment variable 'WEBSITE_HOSTNAME' was null.");

return null;
}

var domain = new Uri(serverUri).Host;

var cookieContainer = new CookieContainer(1);
cookieContainer.Add(new Cookie(AuthenticationConstants.CookieName, cookie, "/", domain));

return cookieContainer;

var container = new CookieContainer(1);
container.Add(new Cookie(name: AuthenticationConstants.CookieName,
value: cookie,
path: "/",
domain: domain));
return container;
}

public async ValueTask DisposeAsync()
Expand Down

0 comments on commit f7de910

Please sign in to comment.