ServiceStack:显示身份验证和身份验证路径

我一直在考虑使用 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)); 

但这隐藏了两条路径。


侃侃尔雅
浏览 195回答 1
1回答

墨色风雨

您可以通过仅指定要注册的 Auth 服务路由来从 AuthFeature 中删除其他路由:Plugins.Add(new AuthFeature(...) {&nbsp; &nbsp; ServiceRoutes = {&nbsp; &nbsp; &nbsp; &nbsp; [typeof(AuthenticateService)] = new[] {"/auth", "/auth/{provider}"}&nbsp; &nbsp; }});
打开App,查看更多内容
随时随地看视频慕课网APP