43 lines
1.2 KiB
Haskell
43 lines
1.2 KiB
Haskell
module Main (main) where
|
|
|
|
import qualified Data.Aeson as A
|
|
import qualified Data.Text as T
|
|
import Nuthatch.Config (HttpConfig (..), secret)
|
|
import Nuthatch.Session (mintSession, newCsrfToken)
|
|
import Nuthatch.Types
|
|
( CsrfToken (..)
|
|
, SessionToken (..)
|
|
)
|
|
import System.Environment (getArgs, lookupEnv)
|
|
|
|
main :: IO ()
|
|
main = do
|
|
[output] <- getArgs
|
|
jwtSecret <- maybe (fail "NUTHATCH_JWT_SECRET is required") pure
|
|
=<< lookupEnv "NUTHATCH_JWT_SECRET"
|
|
token <- mintSession
|
|
(fixtureHttpConfig (T.pack jwtSecret))
|
|
"https://browser-fixture.invalid"
|
|
"browser-user"
|
|
(Just "Browser Fixture")
|
|
>>= either (fail . T.unpack) pure
|
|
csrf <- newCsrfToken
|
|
A.encodeFile output $
|
|
A.object
|
|
[ "session" A..= unSessionToken token
|
|
, "csrf" A..= unCsrfToken csrf
|
|
]
|
|
|
|
fixtureHttpConfig :: T.Text -> HttpConfig
|
|
fixtureHttpConfig jwtSecret = HttpConfig
|
|
{ cfgListenHost = "127.0.0.1"
|
|
, cfgListenPort = 8080
|
|
, cfgTlsCertPath = ""
|
|
, cfgTlsKeyPath = ""
|
|
, cfgPublicBaseUrl = "https://nuthatch.invalid"
|
|
, cfgJwtSecret = secret jwtSecret
|
|
, cfgSessionHours = 1
|
|
, cfgCookieName = "nuthatch_session"
|
|
, cfgCsrfCookieName = "nuthatch_csrf"
|
|
, cfgOidcTransactionCookieName = "nuthatch_oidc"
|
|
}
|