Using Swagger with custom JWT auth

I have this in my config:

          container.Register<IAuthRepository>(new CustomAuthRepository());
            Plugins.Add(new AuthFeature(() => new AuthUserSession(),
                    new IAuthProvider[] {
                    new JwtAuthProvider(AppSettings) {
                        AuthKey = AesUtils.CreateKey(),
                        HashAlgorithm = "RS256",
                        PublicKeyXml = publicXml,
                        PrivateKeyXml = privateKey,
                        RequireSecureConnection = false
                    new CredentialsAuthProvider()
        Plugins.Add(new SwaggerFeature());

I have this service:

    [Route("/web/survey/{SurveyTemplateStatus}", "GET")]
    public class SurveyList : IReturn<List<SurveysResponse>>
        public SurveyTemplateStatus SurveyTemplateStatus { get; set; }

I put the creducials in swagger ui

When I invoke a service I get 401 which is expected. CustomAuthRepository is not invoked.

What am I missing?

Please see Open API docs on Swagger UI Security the only 2 supported Auth methods are BearerToken or Basic Auth which requires the BasicAuthProvider.

1 Like