Comments (4)
It's "bug" in the openapi spec: https://spec.openapis.org/oas/v3.1.0.html#fixed-fields-9
If in is "header" and the name field is "Accept", "Content-Type" or "Authorization", the parameter definition SHALL be ignored.
For authentication you should use security
section instead
from openapi3.
oh, thanks for pointing at the spec section! Let me verify that it works as intended once I add it, and then I'll close the issue.
from openapi3.
Hi,
Thanks for the report. As @stevladimir mentioned, Authorization
should be handled through corresponding mechanism in OpenAPI, not with per-path headers. Look for "security schemes" and "security requirements" in the spec and in this package.
I will close this as there is nothing I can do on the library's part. If you run into problems with defining security schemes, please open a new issue.
from openapi3.
@maksbotan Hi!
I'd like to clarify whether defining security schemes for OpenAPI
values is just enought to enable authorization headers in UI requests to respective endpoints, or is it also a requirement to remove existing "Authorization" headers from endpoint definitions?
I've got this security schema applied:
openApiSpec :: OpenApi
openApiSpec =
-- Combine 'Public' spec
toOpenApi publicSpec
<>
-- with JWT 'Protected' spec so that
(toOpenApi protectedSpec
-- there's a common components section that defines 'myJWT' security scheme under "jwtToken" name
& components . securitySchemes . at "jwtToken" ?~ myJWT
-- and all operations in this part of the spec are required to use "jwtToken" security scheme
& allOperations . security .~ [SecurityRequirement $ mempty & at "jwtToken" ?~ []]
-- and that implies that the endpoints could return 401 alongside normal responses defined elsewhere
& canReturn401Response
) where
myJWT = SecurityScheme (SecuritySchemeHttp . HttpSchemeBearer . Just $ "jwt")
(Just "jwt token")
canReturn401Response = setResponse 401 (pure $ mempty & description .~ "Authorization failed")
I can see that the corresponding OpenAPI spec has properly associated the common securitySchemes
section with endpoints' security
sections, yet the interactive UI is still not sending the Authorization
header when I fill it with a Bearer <token>
value.
Is that because my endpoints are still using Servant's Header "Authorization" JwtValue
combinators alongside OpenApi security definitions?
from openapi3.
Related Issues (20)
- `encodePretty` should be exposed from `Data.OpenApi`
- Invalid schema with types with primes (`'`)
- Generic polymorphic schema handle lists differently to aeson HOT 2
- Outdated documentation re sum encoding differs ToSchema/ToJSON? HOT 1
- Wrong format when generating empty scopes map HOT 2
- Exception when parsing newer OpenApi3 schemas HOT 4
- Add `nullable` attribute HOT 4
- _OpenApiItemsArray and _OpenApiItemsObject should be Prisms, not Reviews
- invalid schema HOT 1
- Structural error at components.schemas.AggregateMRQuery.properties.select.items.items should be object HOT 2
- SecurityDefinitions missing "Index" and "IxValue" type family instances
- SecurityDefinitions missing "Ixed" and "At" type-class instances
- Allow GHC-9.6
- Mismatch between ToJSON and ToSchema with nullary single-record constructor
- How to implement allOperations for optics? HOT 2
- Hardcoded references
- add `ToSchema Schema` instance
- validateJSON semantics with `allOf` seem incorrect
- Why are the schemas different for `ToParamSchema UUID` and `ToSchema UUID`
- Prefix stripping when a `$ref` is parsed as a `Referenced` is confusing HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openapi3.