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

HasOpenApi for BasicAuth #14

Open
gromakovsky opened this issue Nov 3, 2021 · 2 comments
Open

HasOpenApi for BasicAuth #14

gromakovsky opened this issue Nov 3, 2021 · 2 comments

Comments

@gromakovsky
Copy link

BasicAuth is defined in the servant package, so I think it makes sense to have instance HasOpenApi sub => HasOpenApi (BasicAuth realm a :> sub) in servant-openapi3.

There is an old issue about it in servant-swagger: haskell-servant/servant-swagger#34. The last comment there recommends using servant-auth instead, but BasicAuth still exists in servant and is not deprecated, so I think this instance should be useful for some projects. I actually ported this implementation and got something like

instance HasOpenApi sub => HasOpenApi (BasicAuth realm a :> sub) where
  toOpenApi _ = toOpenApi @sub Proxy
    & OpenApi.security <>~ securityRequirements
    & OpenApi.components . OpenApi.securitySchemes <>~ securitySchemes
    where
      oneRequirement req = [OpenApi.SecurityRequirement req]
      securityRequirements =
        oneRequirement $ InsOrd.fromList [("BasicAuth", [])]
      securitySchemes = InsOrd.fromList [("BasicAuth", securityScheme)]
      securityScheme =
        OpenApi.SecurityScheme (OpenApi.SecuritySchemeHttp OpenApi.HttpSchemeBasic) Nothing

which looks in line with https://swagger.io/docs/specification/authentication/basic-authentication/.

So now I can make a PR with this instance, but before doing that I'd like to check whether it's actually needed 🙂

@maksbotan
Copy link
Collaborator

Hi!

I don't mind having this instance in the package. I don't see a lot of sense in it though. Does anyone in the wild use BasicAuth provided by servant?

Feel free to make a PR if you think it should be there, I'll gladly accept it :)

@gdeest
Copy link

gdeest commented Jan 18, 2022

We are also receiving requests on the servant side ( haskell-servant/servant#1505 ), so I think there is a need for these instances (and servant-openapi3 definitely looks like the right place).

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