Skip to content

src/security/samples/StaticFilesAuth always not working #43274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
hylinux opened this issue Aug 14, 2022 · 2 comments · Fixed by #43352
Closed
1 task done

src/security/samples/StaticFilesAuth always not working #43274

hylinux opened this issue Aug 14, 2022 · 2 comments · Fixed by #43352
Assignees
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions investigate
Milestone

Comments

@hylinux
Copy link

hylinux commented Aug 14, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Hi, When I tried to run the sample in : src/Security/Sampels/StaticFilesAuth, look like it was broken. would you help us take a look?

when I tried to run the sample, after login, access the url: /https://localhost:5001/MapAuthenticatedFiles

it willreport Exception:

System.InvalidOperationException: The request reached the end of the pipeline without executing the endpoint: '/'. Please register the EndpointMiddleware using 'IApplicationBuilder.UseEndpoints(...)' if using routing.
   at Microsoft.AspNetCore.Builder.ApplicationBuilder.<>c.<Build>b__18_0(HttpContext context)
   at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.StaticFiles.DirectoryBrowserMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.StaticFiles.DefaultFilesMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authorization.Policy.AuthorizationMiddlewareResultHandler.HandleAsync(RequestDelegate next, HttpContext context, AuthorizationPolicy policy, PolicyAuthorizationResult authorizeResult)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.InvokeCore(HttpContext context, PathString matchedPath, PathString remainingPath)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

I tried to debug into.
I found it will jump here:

      app.Map("/MapAuthenticatedFiles", branch =>
        {
            branch.Use((context, next) => { SetFileEndpoint(context, files, null); return next(context); });
            branch.UseAuthorization();
            SetupFileServer(branch, files);
        });

the werid thing is: it will run into branch.Use( (context, next) => {} ), and then the pipeline was end, will not go through

           branch.UseAuthorization();
            SetupFileServer(branch, files);

would you help to take a look?

thanks

Expected Behavior

it should work success

Steps To Reproduce

No response

Exceptions (if any)

System.InvalidOperationException: The request reached the end of the pipeline without executing the endpoint: '/'. Please register the EndpointMiddleware using 'IApplicationBuilder.UseEndpoints(...)' if using routing.
at Microsoft.AspNetCore.Builder.ApplicationBuilder.<>c.b__18_0(HttpContext context)
at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.StaticFiles.DirectoryBrowserMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.StaticFiles.DefaultFilesMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authorization.Policy.AuthorizationMiddlewareResultHandler.HandleAsync(RequestDelegate next, HttpContext context, AuthorizationPolicy policy, PolicyAuthorizationResult authorizeResult)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.InvokeCore(HttpContext context, PathString matchedPath, PathString remainingPath)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

.NET Version

6.0.400

Anything else?

No response

@adityamandaleeka
Copy link
Member

@Tratcher can you please take a look?

@Tratcher
Copy link
Member

This was regressed by a0513ea#diff-794cdf47625f76680985628eb02bc4a94ec6952dd4c468ec5d9e7ce672cebdb8.

The sample could probably be updated to take advantage of this change. I'll look into it more.

Workaround:
Add this to the start of Startup.SetupFileServer.

        builder.Use((context, next) => { context.SetEndpoint(null); return next(context); });

Tratcher added a commit to Tratcher/aspnetcore that referenced this issue Aug 17, 2022
@Tratcher Tratcher added this to the 8.0-alpha1 milestone Aug 17, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Oct 13, 2022
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Aug 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions investigate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants