diff --git a/yesod-auth/Yesod/Auth/Kerberos.hs b/yesod-auth/Yesod/Auth/Kerberos.hs new file mode 100644 index 00000000..319ee72d --- /dev/null +++ b/yesod-auth/Yesod/Auth/Kerberos.hs @@ -0,0 +1,118 @@ +{-# LANGUAGE QuasiQuotes #-} +{-# LANGUAGE CPP #-} +{-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE OverloadedStrings #-} +-- | In-built kerberos authentication for Yesod. +-- +-- Please note that all configuration should have been done +-- manually on the machine prior to running the code. +-- +-- On linux machines the configuration might be in /etc/krb5.conf. +-- It's worth checking if the Kerberos service provider (e.g. your university) +-- already provide a complete configuration file. +-- +-- Be certain that you can manually login from a shell by typing +-- +-- > kinit username +-- +-- If you fill in your password and the program returns no error code, +-- then your kerberos configuration is setup properly. +-- Only then can this module be of any use. +module Yesod.Auth.Kerberos + ( authKerberos, + genericAuthKerberos, + KerberosConfig(..), + defaultKerberosConfig + ) where + +#include "qq.h" + +import Yesod.Auth +import Web.Authenticate.Kerberos +import Data.Text (Text) +import qualified Data.Text as T +import Text.Hamlet +import Yesod.Handler +import Yesod.Widget +import Control.Monad.IO.Class (liftIO) +import Yesod.Form +import Control.Applicative ((<$>), (<*>)) + +data KerberosConfig = KerberosConfig { + -- | When a user gives username x, f(x) will be passed to Kerberos + usernameModifier :: Text -> Text + -- | When a user gives username x, f(x) will be passed to Yesod + , identifierModifier :: Text -> Text + } + +-- | A configuration where the username the user provides is the one passed +-- to both kerberos and yesod +defaultKerberosConfig :: KerberosConfig +defaultKerberosConfig = KerberosConfig id id + +-- | A configurable version of 'authKerberos' +genericAuthKerberos :: YesodAuth m => KerberosConfig -> AuthPlugin m +genericAuthKerberos config = AuthPlugin "kerberos" dispatch $ \tm -> addHamlet + [hamlet| +