To add JWT authentication to an API, requires this... as per https://swagger.io/docs/specification/authentication/bearer-authentication/
spec, err := api.Spec()
if err != nil {
log.Error("failed to create spec", slog.Any("error", err))
os.Exit(1)
}
spec.Components.SecuritySchemes = map[string]*openapi3.SecuritySchemeRef{
"bearerAuth": {
Value: openapi3.NewJWTSecurityScheme(),
},
}
securitySchemeToScopes := openapi3.NewSecurityRequirement()
securitySchemeToScopes.Authenticate("bearerAuth")
spec.Security = *openapi3.NewSecurityRequirements().
With(securitySchemeToScopes)
Since it's so common, maybe it would be better as:
api.SetAuth(rest.JWTBearerAuth())
spec, err := api.Spec()
if err != nil {
log.Error("failed to create spec", slog.Any("error", err))
os.Exit(1)
}
Not sure about how the API would look to support mixed authentication (some handlers authenticated, some open). Maybe that would be out of scope.
To add JWT authentication to an API, requires this... as per https://swagger.io/docs/specification/authentication/bearer-authentication/
Since it's so common, maybe it would be better as:
Not sure about how the API would look to support mixed authentication (some handlers authenticated, some open). Maybe that would be out of scope.