chore(auth): userLookupAndUpsert
This commit is contained in:
parent
95803db3a0
commit
78a8442d07
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
module Foundation.Yesod.Auth
|
module Foundation.Yesod.Auth
|
||||||
( authenticate
|
( authenticate
|
||||||
-- , ldapLookupAndUpsert -- TODO: remove in favour of fetchUserData
|
, userLookupAndUpsert
|
||||||
, upsertUser
|
, upsertUser
|
||||||
, decodeUserTest
|
, decodeUserTest
|
||||||
, UserConversionException(..)
|
, UserConversionException(..)
|
||||||
@ -114,7 +114,7 @@ authenticate creds@Creds{..} = liftHandler . runDB . withReaderT projectBackend
|
|||||||
| not isDummy, not isOther
|
| not isDummy, not isOther
|
||||||
-- , UserAuthConfSingleSource (AuthSourceConfAzureAdV2 upsertUserAzureConf) <- userAuthConf
|
-- , UserAuthConfSingleSource (AuthSourceConfAzureAdV2 upsertUserAzureConf) <- userAuthConf
|
||||||
, Just upsertMode' <- upsertMode -> do
|
, Just upsertMode' <- upsertMode -> do
|
||||||
userData <- fetchUserData upsertMode' Creds{..}
|
userData <- fetchUserData Creds{..}
|
||||||
$logDebugS "Auth" $ "Successful user data lookup: " <> tshow userData
|
$logDebugS "Auth" $ "Successful user data lookup: " <> tshow userData
|
||||||
Authenticated . entityKey <$> upsertUser upsertMode' userData
|
Authenticated . entityKey <$> upsertUser upsertMode' userData
|
||||||
-- Authenticated . entityKey <$> upsertUser upsertMode' UpsertUserDataAzure{..}
|
-- Authenticated . entityKey <$> upsertUser upsertMode' UpsertUserDataAzure{..}
|
||||||
@ -169,6 +169,19 @@ _upsertUserMode mMode cs@Creds{..}
|
|||||||
defaultOther = apHash
|
defaultOther = apHash
|
||||||
|
|
||||||
|
|
||||||
|
userLookupAndUpsert :: forall m.
|
||||||
|
( MonadHandler m
|
||||||
|
, HandlerSite m ~ UniWorX
|
||||||
|
, MonadMask m
|
||||||
|
, MonadUnliftIO m
|
||||||
|
)
|
||||||
|
=> Text
|
||||||
|
-> UpsertUserMode
|
||||||
|
-> SqlPersistT m (Entity User)
|
||||||
|
userLookupAndUpsert credsIdent mode =
|
||||||
|
fetchUserData Creds{credsPlugin=mempty,credsExtra=mempty,..} >>= upsertUser mode
|
||||||
|
|
||||||
|
|
||||||
data FetchUserDataException
|
data FetchUserDataException
|
||||||
= FetchUserDataNoResult
|
= FetchUserDataNoResult
|
||||||
| FetchUserDataAmbiguous
|
| FetchUserDataAmbiguous
|
||||||
@ -176,24 +189,6 @@ data FetchUserDataException
|
|||||||
deriving (Eq, Ord, Read, Show, Generic)
|
deriving (Eq, Ord, Read, Show, Generic)
|
||||||
deriving anyclass (Exception)
|
deriving anyclass (Exception)
|
||||||
|
|
||||||
-- TODO: deprecate in favour of fetchUserData
|
|
||||||
-- ldapLookupAndUpsert :: forall m.
|
|
||||||
-- ( MonadHandler m
|
|
||||||
-- , HandlerSite m ~ UniWorX
|
|
||||||
-- , MonadMask m
|
|
||||||
-- , MonadUnliftIO m
|
|
||||||
-- )
|
|
||||||
-- => Text
|
|
||||||
-- -> SqlPersistT m (Entity User)
|
|
||||||
-- ldapLookupAndUpsert ident =
|
|
||||||
-- getsYesod (view _appLdapPool) >>= \case
|
|
||||||
-- Nothing -> throwM $ LdapUserLdapError $ LdapHostNotResolved "No LDAP configuration in Foundation."
|
|
||||||
-- Just ldapPool ->
|
|
||||||
-- ldapUser'' ldapPool ident >>= \case
|
|
||||||
-- Nothing -> throwM LdapUserNoResult
|
|
||||||
-- Just ldapData -> upsertUser UpsertUserGuessUser ldapData
|
|
||||||
|
|
||||||
|
|
||||||
-- | Fetch user data with given credentials from external source(s)
|
-- | Fetch user data with given credentials from external source(s)
|
||||||
fetchUserData :: forall m site.
|
fetchUserData :: forall m site.
|
||||||
( MonadHandler m
|
( MonadHandler m
|
||||||
@ -202,10 +197,9 @@ fetchUserData :: forall m site.
|
|||||||
, MonadMask m
|
, MonadMask m
|
||||||
, MonadUnliftIO m
|
, MonadUnliftIO m
|
||||||
)
|
)
|
||||||
=> UpsertUserMode
|
=> Creds site
|
||||||
-> Creds site
|
|
||||||
-> SqlPersistT m (NonEmpty UpsertUserData)
|
-> SqlPersistT m (NonEmpty UpsertUserData)
|
||||||
fetchUserData _upsertMode creds@Creds{..} = do
|
fetchUserData creds@Creds{..} = do
|
||||||
userAuthConf <- getsYesod $ view _appUserAuthConf
|
userAuthConf <- getsYesod $ view _appUserAuthConf
|
||||||
now <- liftIO getCurrentTime
|
now <- liftIO getCurrentTime
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user