From 9562060005eafc7a1755e1d081e1d46e981948cc Mon Sep 17 00:00:00 2001 From: John Rutherford Date: Tue, 3 Sep 2024 18:09:22 -0400 Subject: [PATCH 1/2] fix: duplicate scopes variable name with multiple oauth2 schemes --- gen/_template/security.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gen/_template/security.tmpl b/gen/_template/security.tmpl index 32f695348..cff76adb4 100644 --- a/gen/_template/security.tmpl +++ b/gen/_template/security.tmpl @@ -34,7 +34,7 @@ func findAuthorization(h http.Header, prefix string) (string, bool) { {{ range $s := $.Securities }} {{- if $s.Format.IsOAuth2Security }} -var oauth2Scopes = map[string][]string { +var oauth2Scopes{{ $s.Type.Name }} = map[string][]string { {{- range $operationName, $scopes := $s.Scopes }} {{ quote $operationName }}: []string{ {{- range $scope := $scopes }} @@ -99,7 +99,7 @@ func (s *Server) security{{ $s.Type.Name }}(ctx context.Context, operationName s return ctx, false, nil } t.Token = token - t.Scopes = oauth2Scopes[operationName] + t.Scopes = oauth2Scopes{{ $s.Type.Name }}[operationName] {{- else if $s.Format.IsCustomSecurity }} t := req {{- else }} From b603d861efad376f2695826aa701149767716682 Mon Sep 17 00:00:00 2001 From: John Rutherford Date: Tue, 3 Sep 2024 18:11:07 -0400 Subject: [PATCH 2/2] chore: commit generated files --- examples/ex_oauth2/oas_security_gen.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/ex_oauth2/oas_security_gen.go b/examples/ex_oauth2/oas_security_gen.go index 82dd2f616..b4df68c2d 100644 --- a/examples/ex_oauth2/oas_security_gen.go +++ b/examples/ex_oauth2/oas_security_gen.go @@ -33,7 +33,7 @@ func findAuthorization(h http.Header, prefix string) (string, bool) { return "", false } -var oauth2Scopes = map[string][]string{ +var oauth2ScopesOAuth2 = map[string][]string{ "AddPet": []string{ "admin", }, @@ -55,7 +55,7 @@ func (s *Server) securityOAuth2(ctx context.Context, operationName string, req * return ctx, false, nil } t.Token = token - t.Scopes = oauth2Scopes[operationName] + t.Scopes = oauth2ScopesOAuth2[operationName] rctx, err := s.sec.HandleOAuth2(ctx, operationName, t) if errors.Is(err, ogenerrors.ErrSkipServerSecurity) { return nil, false, nil