我正在使用Service Fabric无状态服务Asp.net&尝试实现Oauth 2.0,但我在Startup.cs& ServiceInstanceListener
无法解析类型' Owin.IAppBuilder'对于参数' appBuilder'方法'配置'在类型' AuthenticationService.Startup
我在StartUp.cs of Service下找不到ConfigureAuth(IAppBuilder应用程序)。
代码:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IAppBuilder appBuilder) {
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
**var config = new HttpConfiguration();
ConfigureOAuth(appBuilder);
appBuilder.UseCors(CorsOptions.AllowAll);
appBuilder.UseWebApi(config);**
}
public void **ConfigureOAuth**(IAppBuilder app)
{
OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions()
{
AllowInsecureHttp = true,
TokenEndpointPath = new PathString("/token"),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
Provider = new SimpleAuthorizationServerProvider()
};
// Token Generation
app.UseOAuthAuthorizationServer(OAuthServerOptions);
app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
}
编辑固定代码块...
答案 0 :(得分:0)
我认为您使用.Net Framework与Owin的引用而不是使用.NET Core。 尝试删除ConfigureOauth方法 并在Startup.cs文件
中的ConfigureServices方法中使用此代码段services.AddAuthentication()
.AddJwtBearer(cfg =>
{
cfg.RequireHttpsMetadata = false;
cfg.SaveToken = true;
cfg.TokenValidationParameters = new TokenValidationParameters()
{
ValidIssuer = Configuration["Tokens:Issuer"],
ValidAudience = Configuration["Tokens:Issuer"],
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Tokens:Key"]))
};
});