graphql-engine/server/src-lib/Data/Parser/Expires.hs
Antoine Leblanc 5b54f9d766
server: add support for webhook connection expiration (#4196)
* add expiry time to webhook user info

This also adds an optional message to webhook errors: if we fail to
parse an expiry time, we will log a warning with the parse error.

* refactored Auth

This change had one main goal: put in common all expiry time
extraction code between the JWT and WebHook parts of the
code. Furthermore, this change also moves all WebHook specific code to
its own module, similarly to what is done for JWT.

* Remove dependency on string-conversions in favor of text-conversions

string-conversions silently uses UTF8 instead of being explicit about
it, and it uses lenientDecode when decoding ByteStrings when it’s
usually better to reject invalid UTF8 input outright. text-conversions
solves both those problems.

Co-authored-by: Alexis King <lexi.lambda@gmail.com>
2020-04-02 19:00:13 -05:00

18 lines
584 B
Haskell

module Data.Parser.Expires
( parseExpirationTime
) where
import Control.Monad.Except
import Data.Text.Conversions
import Data.Time.Clock
import Data.Time.Format (defaultTimeLocale, parseTimeM)
import Hasura.Prelude
-- | Extracts an absolute expiration time from a Expires header.
parseExpirationTime :: MonadError String m => Text -> m UTCTime
parseExpirationTime = fromText
>>> parseTimeM True defaultTimeLocale "%a, %d %b %Y %T GMT"
>>> (`onNothing` throwError "Value of Expires header is not a valid timestamp")