Skip to content
This repository has been archived by the owner on Oct 29, 2021. It is now read-only.

Servant.Auth.Swagger: instances for Tokens? #180

Open
cdupont opened this issue Oct 27, 2020 · 0 comments
Open

Servant.Auth.Swagger: instances for Tokens? #180

cdupont opened this issue Oct 27, 2020 · 0 comments

Comments

@cdupont
Copy link

cdupont commented Oct 27, 2020

I'm using Servant.Auth.Swagger, which is very useful to get authorization displayed in Swagger.
However, in my API I also need to return JWTs:

type TokenAPI = ...   :> Post '[PlainText, JSON] Token

So I defined:

--- Wrapper for JWTs.
newtype Token = Token {unToken :: ByteString} deriving (Eq, Show, Generic)

instance ToJSON Token where
  toJSON (Token t) = String $ convertString t

instance ToSchema Token where
  declareNamedSchema _ = pure (NamedSchema (Just "Token") binarySchema)

instance MimeRender PlainText Token where
  mimeRender _ (Token tok) = tok

I'm wondering is this is already somewhere, or if this could be integrated in Servant.Auth.Swagger.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant