2

So I'm running a Linux VM (DigitalOcean Droplet) to host my ASP.NET Core Minimal API, I've got one endpoint that requires a refresh token to be supplied in the header and have done so using the following parameter/annotation in the MapPost call

app.MapPost("/auth/refresh",
    [AllowAnonymous] async (HttpRequest request, DataContext context, [FromHeader(Name = "refresh_token") ] string refresh_token) => { functionality here }

But when I fill in the header and hit send on the Swagger UI, it fails to recognise the header value - only when hosted on the VM, using localhost on my PC seems to be working fine. Gives me this error before it even steps into the function block

Microsoft.AspNetCore.Http.BadHttpRequestException: Required parameter "string refresh_token" was not provided from header. at Microsoft.AspNetCore.Http.RequestDelegateFactory.Log.RequiredParameterNotProvided(HttpContext httpContext, String parameterTypeName, String parameterName, String source, Boolean shouldThrow) at lambda_method4(Closure , Object , HttpContext ) at Microsoft.AspNetCore.Http.RequestDelegateFactory.<>c__DisplayClass36_0.b__0(HttpContext httpContext) at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext) End of stack trace from previous location --- at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext) at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

HEADERS

=======

Accept: /

Connection: keep-alive

Host: randomtestdomain.site

User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36

Accept-Encoding: gzip, deflate, br

Accept-Language: en-US,en;q=0.9

Origin: https://randomtestdomain.site

Referer: https://randomtestdomain.site/swagger/index.html

Content-Length: 0

X-Forwarded-For: 175.36.206.175

X-Forwarded-Proto: https

sec-ch-ua: "Not?A_Brand";v="8", "Chromium";v="108", "Google Chrome";v="108"

sec-ch-ua-mobile: ?0

sec-ch-ua-platform: "Windows"

Sec-Fetch-Site: same-origin

Sec-Fetch-Mode: cors

Sec-Fetch-Dest: empty

As pictured, I checked the network tab on Chrome to see that the header was being attached properly and it wasn't an issue with the swagger UI, all appears fine in that regard.see here

Also tried using app.UseForwardedHeaders() to no avail.

Let me know if more of the source is needed to discern the issue or if this might be a DNS forwarding issue or something, since I wouldn't expect it to be code-related I've kept it light but relevant.

Guru Stron
  • 102,774
  • 10
  • 95
  • 132

1 Answers1

0

Based on headers provided looks like you are using some kind of reverse proxy in your VM setup - check if it is setup correctly to pass through all needed headers (like here was done for Nginx).

Guru Stron
  • 102,774
  • 10
  • 95
  • 132