Gavin Beard
Gavin Beard

Reputation: 199

ServiceStack: Showing both auth and authenticate paths

I've been looking at using ServiceStack to create a lightweight rest api and notice that when I look in the swagger-ui I notice there is an auth endpoint and an authenticate which both seem to do exactly the same thing.

My config. code is:

    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));
    }

Is there a way to just show the /auth endpoint and hide the other? I tried using:

typeof(Authenticate).AddAttributes(new ExcludeAttribute(Feature.Metadata)); 

but this hides both paths.

Upvotes: 1

Views: 96

Answers (1)

mythz
mythz

Reputation: 143319

You can remove additional routes from the AuthFeature by only specifying the Auth Service Routes you want registered with:

Plugins.Add(new AuthFeature(...) {
    ServiceRoutes = {
        [typeof(AuthenticateService)] = new[] {"/auth", "/auth/{provider}"}
    }
});

Upvotes: 1

Related Questions