n host params = do
  let domain = fromMaybe "localhost" host
  isTestMode ← getConfOpt testMode
  --let isTestMode = False
  if isTestMode
     then makeAccessToken domain
       (fromMaybe "unknown" $ lookup "me" params)
       (fromMaybe "post create update delete read follow mute block channels" $ lookup "scope" params)
       "example.com"
     else do
       checkURI ← getConfOpt indieauthCheckEndpoint
       resp0 ← runHTTP $ reqS checkURI >>= postForm params >>= performWithBytes
       case (note "Could not read form" . readForm) =<< responseBody <$> resp0 of
         Right (indieAuthRespParams ∷ [(Text, Text)]) → do
           let me = orEmptyMaybe $ lookup "me" indieAuthRespParams
           guardBool errWrongAuth $ Just domain == fmap (cs . uriRegName) (uriAuthority $ fromMaybe nullURI $ parseURI $ cs me)
           logWarn $ "Authenticated a client: " ++ display (fromMaybe "unknown" $ lookup "client_id" params)
           makeAccessToken domain me
                           (fromMaybe "post" $ lookup "scope" indieAuthRespParams)
                           (fromMaybe "" $ lookup "client_id" params)
         Left e → do
           logInfo $ "Authentication error: " ++ display e ++ " / params: " ++ display (tshow params)
           throwM errWrongAuth

-- | Internal "client" (redirect_uri target)
getSelfLogin ∷ Maybe Text → Maybe Text → Maybe Text → Maybe Text → Sweetroll NoContent
ge
postLogin ∷ Maybe Text → [(Text, Text)] → Sweetroll AccessToken
postLogin host params = do
  let domain = fromMaybe "localhost" host
  isTestMode ← getConfOpt testMode
  --let isTestMode = False
  if isTestMode
     then makeAccessToken domain
       (fromMaybe "unknown" $ lookup "me" params)
       (fromMaybe "post create update delete read follow mute block channels" $ lookup "scope" params)
       "example.com"
     else do
       checkURI ← getConfOpt indieauthCheckEndpoint
       resp0 ← runHTTP $ reqS checkURI >>= postForm params >>= performWithBytes
       case (note "Could not read form" . readForm) =<< responseBody <$> resp0 of
         Right (indieAuthRespParams ∷ [(Text, Text)]) → do
           let me = orEmptyMaybe $ lookup "me" indieAuthRespParams
           guardBool errWrongAuth $ Just domain == fmap (cs . uriRegName) (uriAuthority $ fromMaybe nullURI $ parseURI $ cs me)
           logWarn $ "Authenticated a client: " ++ display (fromMaybe "unknown" $ lookup "client_id" params)
           makeAccessToken domain me
                           (fromMaybe "post" $ lookup "scope" indieAuthRespParams)
                           (fromMaybe "" $ lookup "client_id" params)
         Left e → do
           logInfo $ "Authentication error: " ++ display e ++ " / params: " ++ display (tshow params)
           throwM errWrongAuth

-- | Internal "client" (redirect_uri target)
postLogin host params = do
  let domain = fromMaybe "localhost" host
  isTestMode ← getConfOpt testMode
  --let isTestMode = False
  if isTestMode
     then makeAccessToken domain
       (fromMaybe "unknown" $ lookup "me" params)
       (fromMaybe "post create update delete read follow mute block channels" $ lookup "scope" params)
       "example.com"
     else do
       checkURI ← getConfOpt indieauthCheckEndpoint
       resp0 ← runHTTP $ reqS checkURI >>= postForm params >>= performWithBytes
       case (note "Could not read form" . readForm) =<< responseBody <$> resp0 of
         Right (indieAuthRespParams ∷ [(Text, Text)]) → do
           let me = orEmptyMaybe $ lookup "me" indieAuthRespParams
           guardBool errWrongAuth $ Just domain == fmap (cs . uriRegName) (uriAuthority $ fromMaybe nullURI $ parseURI $ cs me)
           logWarn $ "Authenticated a client: " ++ display (fromMaybe "unknown" $ lookup "client_id" params)
           makeAccessToken domain me
                           (fromMaybe "post" $ lookup "scope" indieAuthRespParams)
                           (fromMaybe "" $ lookup "client_id" params)
         Left e → do
           logInfo $ "Authentication error: " ++ display e ++ " / params: " ++ display (tshow params)
           throwM errWrongAuth

-- | Internal "client" (redirect_uri target)