ASPNet Core:将[Authorize]与服务中的功能一起使用

MBS*_*MBS 5 c# asp.net-core

我正在使用JwtBearer身份验证来保护我的API。我在[Authorize]每个API上方都添加了它,并且有效。

我正在使用以下代码在启动时添加身份验证:

services.AddAuthentication("Bearer")
        .AddJwtBearer("Bearer", options =>
        {
            options.Authority = "http://localhost:1234";
            options.RequireHttpsMetadata = false;
            options.Audience = "test";
        });
Run Code Online (Sandbox Code Playgroud)

我想要一种添加[Authorize]到服务中函数的方法,或在函数中编写与相同的代码[Authorize]