summaryrefslogtreecommitdiff
path: root/fig-web/src/Fig/Web/Auth.hs
blob: fa7f9d0bf2066b3a5b8ea6761d3bff679e1e0c75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
module Fig.Web.Auth
  ( Credentials(..)
  , authed
  ) where

import Fig.Prelude

import qualified Data.Text as Text
import qualified Web.Scotty as Sc

import Fig.Web.Types
import Fig.Web.Utils

data Credentials = Credentials
  { user :: Text
  , twitchId :: Text
  }
authed :: SecureModuleArgs -> (Credentials -> Sc.ActionM ()) -> Sc.ActionM ()
authed args h | args.options.simAuth = do
  let auth = Credentials { user = "lcolonq", twitchId = "866686220" }
  h auth
authed _ h = do
  muser <- header "Remote-User"
  memail <- header "Remote-Email"
  case (muser, memail) of
    (Just user, Just email) | twitchId:_ <- Text.splitOn "@" email -> do
      let auth = Credentials{..}
      h auth
    _else -> do
      status status401
      respondText "you're not logged in buddy (this is probably a bug, go message clonk)"