Code Monkey home page Code Monkey logo

Comments (4)

stevladimir avatar stevladimir commented on August 24, 2024

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.

coderfromhere avatar coderfromhere commented on August 24, 2024

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.

maksbotan avatar maksbotan commented on August 24, 2024

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.

coderfromhere avatar coderfromhere commented on August 24, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.