Попытка реализовать токен owin и bearer в проекте Web API ASP. NET Core 3.1 - PullRequest
0 голосов
/ 25 марта 2020

Я пытаюсь настроить в своем проекте ASP. NET Core 3.1 Web API токен-носитель owin для моего API. Отсюда я следовал руководству:

https://bitoftech.net/2014/06/01/token-based-authentication-asp-net-web-api-2-owin-asp-net-identity/

Но в моем проекте компоновщик приложений не тот:

public void ConfigureOAuth(IAppBuilder app)
{
        OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions()
        {
            AllowInsecureHttp = true,
            TokenEndpointPath = new PathString("/token"),
            AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
            Provider = new RoundTableAuthorizationServerProvider()
        };

        // Token Generation
        app.UseOAuthAuthorizationServer(OAuthServerOptions);
        app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
 }

 public Startup(IConfiguration configuration)
 {
     Configuration = configuration;           
 }

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseSwagger();

        app.UseSwaggerUI(c =>
        {
            c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
        });

        app.UseRouting();
        // Enable the application to use bearer tokens to authenticate users
        ConfigureOAuth(app);

        app.UseAuthorization();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
        });
}

Затем в моем методе Configure я пытаюсь вызвать функцию конфигурации, но, поскольку она использует IApplicationBuilder, она не совместима; есть ли более свежее руководство для owin?

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseSwagger();
        app.UseSwaggerUI(c =>
        {
            c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
        });

        app.UseRouting();

        // Enable the application to use bearer tokens to authenticate users
        ConfigureOAuth(app);

        app.UseAuthorization();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
        });
  }

Кроме того, я не могу найти AuthRepository где-нибудь в классах. net - это сторонняя вещь?

...