Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applying AuthenticationFunc for subrouter #825

Open
katyatrue opened this issue Aug 11, 2023 · 2 comments
Open

Applying AuthenticationFunc for subrouter #825

katyatrue opened this issue Aug 11, 2023 · 2 comments

Comments

@katyatrue
Copy link

katyatrue commented Aug 11, 2023

Hi.

I'm using your great library in combination with https://github.com/deepmap/oapi-codegen in order to migrate custom endpoints to openApi one by one.
To reach this I defined openApi endpoints in yml file and used dedicated subrouter.
The problem was that authentication was not properly applied for endpoints defined on subrouter (while on the main router it was working fine).

So for the options:

import (
   chi_middleware "github.com/deepmap/oapi-codegen/pkg/chi-middleware"
)
opts := chi_middleware.Options{
		Options: openapi3filter.Options{
			AuthenticationFunc: func(ctx context.Context, input *openapi3filter.AuthenticationInput) error {
				return openapifilterAuthenticationFunc(ctx, input)
			},
		},
	}

used like that:

 v2r := mux.NewRouter().PathPrefix("/api/test").Subrouter()
 v2r.Use(chi_middleware.OapiRequestValidatorWithOptions(doc, &opts))

my authentication test doesn't pass

while if I am defining options for the whole router:
mux.NewRouter().Use(chi_middleware.OapiRequestValidatorWithOptions(doc, &opts))
then authentication tests are passed

I want to authenticate with AuthenticationFunc on subrouter as it provides much more flexibility on migration scenarios

Is there a way to fix it?

@fenollp
Copy link
Collaborator

fenollp commented Aug 26, 2023

Were you able to find some help over at chi_middleware ?

@jamietanna
Copy link
Contributor

Hey both - I think this question was largely around "can we tweak the openapi3filter.Filter to only match against a subpath within the router, or does it have to be applied to the whole path", hence why we raised it here instead of at oapi-codegen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants