我一直在使用ServiceStack创建一个轻量级的rest api,并注意到当我查看swagger-ui时,我注意到有一个auth端点和一个authenticate,它们似乎都在做完全相同的事情。
我的配置。代码是:
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));
但这会隐藏两条路径。
答案 0 :(得分:1)
您可以仅通过指定要向其注册的Auth服务路由来从AuthFeature中删除其他路由:
Plugins.Add(new AuthFeature(...) {
ServiceRoutes = {
[typeof(AuthenticateService)] = new[] {"/auth", "/auth/{provider}"}
}
});