@@ -130,62 +130,30 @@ import Control.Category ((.), id)
130130import Control.Exception (SomeException )
131131import qualified Control.Exception as E
132132import Control.Lens ((?=) , (.=) , (^.) , (.~) , makeLenses , view , set )
133- -- import Control.Lens.At (IxValue(..), Ixed(..), Index(..), At(at))
134- -- import Control.Monad.Trans (MonadIO(liftIO))
135- -- import Control.Monad.Reader (ask)
136- -- import Control.Monad.State (get, put, modify)
137133import Data.Aeson (FromJSON (.. ), ToJSON (.. ), Result (.. ), fromJSON )
138134import qualified Data.Aeson as A
139135import Data.Aeson.Types (Options (fieldLabelModifier ), defaultOptions , genericToJSON , genericParseJSON )
140- -- import Data.Acid (AcidState, Update, Query, makeAcidic)
141- -- import Data.Acid.Advanced (update', query')
142- -- import Data.ByteString.Base64 (encode)
143- -- import qualified Data.ByteString.Char8 as B
144136import Data.Data (Data , Typeable )
145- -- import Data.Default (def)
146137import Data.Map (Map )
147138import qualified Data.Map as Map
148139import Data.Maybe (fromMaybe , maybeToList )
149140import Data.Monoid ((<>) , mconcat , mempty )
150141import Data.SafeCopy (SafeCopy , Migrate (.. ), base , deriveSafeCopy , extension )
151142import Data.IxSet.Typed
152143import qualified Data.IxSet.Typed as IxSet
153- -- import Data.Set (Set)
154- -- import qualified Data.Set as Set
155144import Data.Text (Text )
156145import qualified Data.Text as Text
157146import qualified Data.Text.Encoding as Text
158- -- import Data.Time (UTCTime, addUTCTime, diffUTCTime, getCurrentTime)
159- -- import Data.Time.Clock.POSIX (utcTimeToPOSIXSeconds, posixSecondsToUTCTime)
160147import Data.UserId (UserId (.. ), rUserId , succUserId , unUserId )
161148import GHC.Generics (Generic )
162- -- import Happstack.Server (Cookie(secure), CookieLife(Session, MaxAge), Happstack, ServerPartT, Request(rqSecure), Response, addCookie, askRq, expireCookie, getHeaderM, lookCookie, lookCookieValue, mkCookie, notFound, toResponseBS)
163- -- import Happstack.Server.Internal.Clock (getApproximateUTCTime)
164- -- import Language.Javascript.JMacro
165149import Prelude hiding ((.) , id , exp )
166150import System.IO (IOMode (ReadMode ), withFile )
167- -- import System.Random (randomRIO)
168151import Text.Boomerang.TH (makeBoomerangs )
169152import Text.Shakespeare.I18N (RenderMessage (renderMessage ), mkMessageFor )
170- import Web.JWT (Algorithm (HS256 ), JWT , VerifiedJWT , JWTClaimsSet (.. ), encodeSigned , claims , decode , decodeAndVerifySignature , secondsSinceEpoch , intDate , verify )
171- import qualified Web.JWT as JWT
172- #if MIN_VERSION_jwt(0,8,0)
173- import Web.JWT (ClaimsMap (.. ), hmacSecret )
174- #else
175- import Web.JWT (secret )
176- #endif
177-
178153import Web.Routes (RouteT , PathInfo (.. ), nestURL )
179154import Web.Routes.Boomerang
180- -- import Web.Routes.Happstack ()
181155import Web.Routes.TH (derivePathInfo )
182156
183- #if MIN_VERSION_jwt(0,8,0)
184- #else
185- unClaimsMap = id
186- #endif
187-
188-
189157-- | when creating JSON field names, drop the first character. Since
190158-- we are using lens, the leading character should always be _.
191159jsonOptions :: Options
@@ -214,38 +182,14 @@ data CoreError
214182 deriving (Eq , Ord , Read , Show , Data , Typeable , Generic )
215183instance ToJSON CoreError where toJSON = genericToJSON jsonOptions
216184instance FromJSON CoreError where parseJSON = genericParseJSON jsonOptions
217- {-
218- instance ToJExpr CoreError where
219- toJExpr = toJExpr . toJSON
220- -}
185+
221186deriveSafeCopy 0 'base ''CoreError
222187
223188mkMessageFor " HappstackAuthenticateI18N" " CoreError" " messages/core" (" en" )
224189
225190------------------------------------------------------------------------------
226191
227- ------------------------------------------------------------------------------
228- -- UserId
229- ------------------------------------------------------------------------------
230- {-
231- -- | a 'UserId' uniquely identifies a user.
232- newtype UserId = UserId { _unUserId :: Integer }
233- deriving (Eq, Ord, Enum, Read, Show, Data, Typeable, Generic)
234- deriveSafeCopy 1 'base ''UserId
235- makeLenses ''UserId
236- makeBoomerangs ''UserId
237-
238- instance ToJSON UserId where toJSON (UserId i) = toJSON i
239- instance FromJSON UserId where parseJSON v = UserId <$> parseJSON v
240-
241- instance PathInfo UserId where
242- toPathSegments (UserId i) = toPathSegments i
243- fromPathSegments = UserId <$> fromPathSegments
244-
245- -- | get the next `UserId`
246- succUserId :: UserId -> UserId
247- succUserId (UserId i) = UserId (succ i)
248- -}
192+
249193------------------------------------------------------------------------------
250194-- Username
251195------------------------------------------------------------------------------
@@ -346,7 +290,8 @@ data AuthenticateURL
346290 AuthenticationMethods (Maybe (AuthenticationMethod , [Text ]))
347291 | HappstackAuthenticateClient
348292 | Logout
349- -- | AmAuthenticated
293+ | AmAuthenticated
294+ | InitClient
350295 deriving (Eq , Ord , Read , Show , Data , Typeable , Generic )
351296
352297makeBoomerangs ''AuthenticateURL
@@ -358,7 +303,8 @@ authenticateURL =
358303 " authentication-methods" </> ( rAuthenticationMethods . rMaybe authenticationMethod)
359304 <> " happstack-authenticate-client" . rHappstackAuthenticateClient
360305 <> " logout" . rLogout
361- -- <> "am-authenticated" . rAmAuthenticated
306+ <> " am-authenticated" . rAmAuthenticated
307+ <> " init-client" . rInitClient
362308 )
363309 where
364310 userId = rUserId . integer
@@ -377,20 +323,39 @@ nestAuthenticationMethod :: (PathInfo methodURL) =>
377323nestAuthenticationMethod authenticationMethod =
378324 nestURL $ \ methodURL -> AuthenticationMethods $ Just (authenticationMethod, toPathSegments methodURL)
379325
326+ ------------------------------------------------------------------------------
327+ -- ClientInitData
328+ ------------------------------------------------------------------------------
329+
330+ -- | The `Token` type represents the data used to identify a user. The
331+ -- name used to make more sense and it should probably be renamed.
332+ data ClientInitData = ClientInitData
333+ { _cidUser :: Maybe User
334+ , _cidPostLoginRedirectURL :: Maybe Text
335+ , _cidPostSignupRedirectURL :: Maybe Text
336+ }
337+ deriving (Eq , Ord , Read , Show , Data , Typeable , Generic )
338+ makeLenses ''ClientInitData
339+ instance ToJSON ClientInitData where toJSON = genericToJSON jsonOptions
340+ instance FromJSON ClientInitData where parseJSON = genericParseJSON jsonOptions
341+
342+ ------------------------------------------------------------------------------
343+ -- Token
344+ ------------------------------------------------------------------------------
380345
381- -- | The `Token` type represents the encrypted data used to identify a
382- -- user .
346+ -- | The `Token` type represents the data used to identify a user. The
347+ -- name used to make more sense and it should probably be renamed .
383348data Token = Token
384349 { _tokenUser :: User
385- , _tokenIsAuthAdmin :: Bool
386350 }
387351 deriving (Eq , Ord , Read , Show , Data , Typeable , Generic )
388352makeLenses ''Token
389353instance ToJSON Token where toJSON = genericToJSON jsonOptions
390354instance FromJSON Token where parseJSON = genericParseJSON jsonOptions
391355
356+
392357------------------------------------------------------------------------------
393- -- Token / TokenText
358+ -- TokenText
394359------------------------------------------------------------------------------
395360
396361-- | `TokenText` is the encrypted form of the `Token` which is passed
0 commit comments