Skip to content

Commit

Permalink
access endpoint wip
Browse files Browse the repository at this point in the history
  • Loading branch information
smatting committed Oct 5, 2022
1 parent 3df3c66 commit 00ed245
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 7 deletions.
59 changes: 53 additions & 6 deletions services/brig/src/Brig/API/Auth.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,61 @@

module Brig.API.Auth where

import Brig.API.Error (authMissingCookie, throwStd)
import Brig.API.Handler
import Data.List.NonEmpty (NonEmpty)
import Debug.Trace
import qualified Brig.ZAuth as ZAuth
import Data.List.NonEmpty (NonEmpty ((:|)))
import qualified Data.List.NonEmpty as NE
import qualified Data.ZAuth.Token as ZAuth
import Imports
import Wire.API.Routes.Public.Brig
import Wire.API.Routes.Public.Brig (SomeUserToken)
import Wire.API.Routes.Public.Brig hiding (SomeUserToken)

access :: NonEmpty SomeUserToken -> Maybe SomeAccessToken -> Handler r Text
access ut at = do
traceM $ "user tokens: " <> show ut
traceM $ "access token: " <> show at
access ut mat = do
tokens <- partitionTokens ut
case (tokens, mat) of
(Left userTokens, Just (AccessToken mat)) ->
error "TODO"

-- traceM $ "user tokens: " <> show ut
-- traceM $ "access token: " <> show at
pure "OK"
where
renewAccess uts mat = error "TODO"

partitionTokens ::
NonEmpty SomeUserToken ->
Handler
r
( Either
(NonEmpty (ZAuth.Token ZAuth.User))
(NonEmpty (ZAuth.Token ZAuth.LegalHoldUser))
)
partitionTokens tokens =
case partitionEithers (map toEither (NE.toList tokens)) of
(at : ats, []) -> pure (Left (at :| ats))
([], lt : lts) -> pure (Right (lt :| lts))
([], []) -> throwStd authMissingCookie -- impossible
(_ats, _rts) -> throwStd authMissingCookie
where
toEither :: SomeUserToken -> Either (ZAuth.Token ZAuth.User) (ZAuth.Token ZAuth.LegalHoldUser)
toEither = error "TODO"

-- renew = \case
-- Nothing ->
-- const $ throwStd authMissingCookie
-- (Just (Left userTokens)) ->
-- -- normal UserToken, so we want a normal AccessToken
-- fmap Left . wrapHttpClientE . renewAccess userTokens <=< matchingOrNone leftToMaybe
-- (Just (Right legalholdUserTokens)) ->
-- -- LegalholdUserToken, so we want a LegalholdAccessToken
-- fmap Right . wrapHttpClientE . renewAccess legalholdUserTokens <=< matchingOrNone rightToMaybe
-- where
-- renewAccess uts mat =
-- Auth.renewAccess uts mat !>> zauthError
-- matchingOrNone :: (a -> Maybe b) -> Maybe a -> (Handler r) (Maybe b)
-- matchingOrNone matching = traverse $ \accessToken ->
-- case matching accessToken of
-- Just m -> pure m
-- Nothing -> throwStd authTokenMismatch
2 changes: 1 addition & 1 deletion services/brig/src/Brig/ZAuth.hs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ newLegalHoldUserToken u = liftZAuth $ do
let LegalHoldUserTokenTimeout ttl = z ^. settings . legalHoldUserTokenTimeout
in ZC.legalHoldUserToken ttl (toUUID u) r

newLegalHoldAccessToken :: MonadZAuth m => (Token LegalHoldUser) -> m (Token LegalHoldAccess)
newLegalHoldAccessToken :: MonadZAuth m => Token LegalHoldUser -> m (Token LegalHoldAccess)
newLegalHoldAccessToken xt = liftZAuth $ do
z <- ask
liftIO $
Expand Down

0 comments on commit 00ed245

Please sign in to comment.