c# - 尝试在 Web API 项目 ASP.NET Core 3.1 中实现 owin 和承载令牌
问题描述
我正在尝试在我的 ASP.NET Core 3.1 Web API 项目中设置我的 api 的 owin 持有者令牌。我从这里遵循了指南:
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 类中的任何地方都找不到 - 这是第三方的事情吗?
解决方案
推荐阅读
- python - 无法在 Windows 或 Mac OS 上安装 MOSAIC
- c# - 在 ASP.NET Core 3.1 MVC 中使用全球化和本地化时命名空间的作用
- java - 用户'root'@'localhost'的访问被拒绝-Spring Boot和MySQL连接
- r - R KNN 错误 - knn 中的错误(training_data,validation_data,training_data$Award.,k = 7):“train”和“class”的长度不同
- f# - 在 Deedle 中对列进行分组
- python-3.x - 获取可移植(gnu)Makefile 使用模式规则对匹配正则表达式的子目录中的文件进行操作
- javascript - 用于自定义交易的 Netsuite 交易摘要框
- r - 在列列表中添加几个滞后/移位
- java - 与 netty 相比,为什么下面的 Java NIO API 这么慢
- reactjs - ExpressJS 的 React Cors 问题