ServiceStack:显示auth和authenticate路径
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ServiceStack:显示auth和authenticate路径相关的知识,希望对你有一定的参考价值。
我一直在寻找使用ServiceStack创建一个轻量级的api 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));
但这隐藏了两条路径。
答案
您只需指定要注册的Auth服务路由,即可从AuthFeature中删除其他路由:
Plugins.Add(new AuthFeature(...)
ServiceRoutes =
[typeof(AuthenticateService)] = new[] "/auth", "/auth/provider"
);
以上是关于ServiceStack:显示auth和authenticate路径的主要内容,如果未能解决你的问题,请参考以下文章
在 UI Firebase Auth Flutter 中显示异常错误