我一直在考虑使用 ServiceStack 来创建一个轻量级的 rest api,并注意到当我查看 swagger-ui 时,我注意到有一个 auth 端点和一个身份验证,它们似乎都在做同样的事情。
我的配置。代码是:
public override void Configure(Container container)
{
//Set Json as default content type
SetConfig(new HostConfig
{
DefaultContentType = MimeTypes.Json
});
//Create connection to sql server DB
var sqlDb = new OrmLiteConnectionFactory("*connection string*", SqlServer2016Dialect.Provider)
{
ConnectionFilter = x => new ProfiledDbConnection(x, Profiler.Current)
};
container.Register<IDbConnectionFactory>(sqlDb);
//Auth Feature setup
Plugins.Add(new AuthFeature(() => new AuthUserSession(),
new IAuthProvider[]
{
new ApiKeyAuthProvider(AppSettings)
{
KeyTypes = new [] { "secret", "publishable" }
},
new BasicAuthProvider(),
new FacebookAuthProvider(AppSettings),
new CredentialsAuthProvider()
})
{
IncludeRegistrationService = true
}
);
//Registration Plugin
Plugins.Add(new RegistrationFeature());
//Mini Profiler
Plugins.Add(new MiniProfilerFeature());
//Swagger ui
Plugins.Add(new SwaggerFeature());
//Setup memory cache
container.Register<ICacheClient>(new MemoryCacheClient());
//setup user auth repo in Sql Server instance
var userRep = new OrmLiteAuthRepository(sqlDb);
userRep.InitSchema();
container.Register<IUserAuthRepository>(userRep);
//Exclude metadata
typeof(AssignRoles).AddAttributes(new ExcludeAttribute(Feature.Metadata));
typeof(UnAssignRoles).AddAttributes(new ExcludeAttribute(Feature.Metadata));
}
有没有办法只显示 /auth 端点并隐藏另一个?我尝试使用:
typeof(Authenticate).AddAttributes(new ExcludeAttribute(Feature.Metadata));
但这隐藏了两条路径。
墨色风雨
相关分类