-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use UUIDs * Add a comment * Add missing fields to 'ListResponse' * Serve a single user * Give the user an email * Resource types * Address comments
- Loading branch information
Artyom Kazak
committed
Sep 10, 2018
1 parent
7b9bdb5
commit 5a402d3
Showing
14 changed files
with
287 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,87 @@ | ||
{-# LANGUAGE QuasiQuotes #-} | ||
|
||
module Main where | ||
|
||
import Web.SCIM.Util | ||
import Web.SCIM.Server | ||
import Web.SCIM.Server.Mock | ||
import Web.SCIM.Class.Auth (Admin (..)) | ||
import Web.SCIM.Capabilities.MetaSchema (empty) | ||
import Web.SCIM.Schema.Meta hiding (meta) | ||
import Web.SCIM.Schema.Common as Common | ||
import Web.SCIM.Schema.ResourceType hiding (name) | ||
import Web.SCIM.Schema.User as User | ||
import Web.SCIM.Schema.User.Name | ||
import Web.SCIM.Schema.User.Email as E | ||
import Web.SCIM.Class.Auth | ||
import Web.SCIM.Capabilities.MetaSchema as MetaSchema | ||
|
||
import Data.Time | ||
import Network.Wai.Handler.Warp | ||
import qualified STMContainers.Map as STMMap | ||
import Control.Monad.STM (atomically) | ||
import Data.UUID as UUID | ||
import Text.Email.Validate | ||
|
||
main :: IO () | ||
main = do | ||
auth <- STMMap.newIO | ||
atomically $ STMMap.insert (Admin "admin", "password") "admin" auth | ||
storage <- TestStorage <$> STMMap.newIO <*> STMMap.newIO <*> pure auth | ||
run 9000 =<< app empty (nt storage) | ||
storage <- TestStorage <$> mkUserDB <*> STMMap.newIO <*> mkAuthDB | ||
run 9000 =<< app MetaSchema.empty (nt storage) | ||
|
||
-- | Create a UserDB with a single user: | ||
-- | ||
-- @ | ||
-- UserID: sample-user | ||
-- @ | ||
mkUserDB :: IO UserStorage | ||
mkUserDB = do | ||
db <- STMMap.newIO | ||
now <- getCurrentTime | ||
let meta = Meta | ||
{ resourceType = UserResource | ||
, created = now | ||
, lastModified = now | ||
, version = Weak "0" -- we don't support etags | ||
, location = Common.URI [relativeUri|/Users/sample-user|] | ||
} | ||
-- Note: Okta required at least one email, 'active', 'name.familyName', | ||
-- and 'name.givenName'. We might want to be able to express these | ||
-- constraints in code (and in the schema we serve) without turning this | ||
-- library into something that is Okta-specific. | ||
let email = Email | ||
{ E.typ = Just "work" | ||
, E.value = maybe (error "couldn't parse email") EmailAddress2 | ||
(emailAddress "elton@wire.com") | ||
, E.primary = Nothing | ||
} | ||
let user = User.empty | ||
{ userName = "elton" | ||
, name = Just Name | ||
{ formatted = Just "Elton John" | ||
, familyName = Just "John" | ||
, givenName = Just "Elton" | ||
, middleName = Nothing | ||
, honorificPrefix = Nothing | ||
, honorificSuffix = Nothing | ||
} | ||
, active = Just True | ||
, emails = Just [email] | ||
} | ||
atomically $ STMMap.insert (WithMeta meta (WithId "elton" user)) "elton" db | ||
pure db | ||
|
||
-- | Create an AuthDB with a single admin: | ||
-- | ||
-- @ | ||
-- UUID: 00000500-0000-0000-0000-000000000001 | ||
-- pass: password | ||
-- @ | ||
-- | ||
-- The authorization header for this admin (which you can regenerate by | ||
-- following the logic in 'authHeader'): | ||
-- | ||
-- @Basic MDAwMDA1MDAtMDAwMC0wMDAwLTAwMDAtMDAwMDAwMDAwMDAxOnBhc3N3b3Jk@ | ||
mkAuthDB :: IO AdminStorage | ||
mkAuthDB = do | ||
db <- STMMap.newIO | ||
let uuid = UUID.fromWords 0x500 0 0 1 | ||
atomically $ STMMap.insert (Admin uuid, "password") uuid db | ||
pure db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{-# LANGUAGE QuasiQuotes #-} | ||
|
||
module Web.SCIM.Schema.ResourceType where | ||
|
||
import Prelude hiding (map) | ||
|
||
import Data.Text (Text) | ||
import Data.Aeson | ||
|
||
import Web.SCIM.Util | ||
import Web.SCIM.Schema.Common | ||
import Web.SCIM.Schema.Schema (Schema(..)) | ||
|
||
import GHC.Generics (Generic) | ||
|
||
-- | Supported resource types. Each resource type also corresponds to an | ||
-- endpoint, described by 'ResourceTypeEndpoint'. | ||
data ResourceType | ||
= UserResource | ||
| GroupResource | ||
deriving (Show, Eq) | ||
|
||
instance ToJSON ResourceType where | ||
toJSON UserResource = "User" | ||
toJSON GroupResource = "Group" | ||
|
||
-- | Definitions of endpoints, returned by @/ResourceTypes@. | ||
data Resource = Resource | ||
{ name :: Text | ||
, endpoint :: URI | ||
, schema :: Schema | ||
} deriving (Show, Eq, Generic) | ||
|
||
instance ToJSON Resource where | ||
toJSON = genericToJSON serializeOptions | ||
|
||
---------------------------------------------------------------------------- | ||
-- Available resource endpoints | ||
|
||
usersResource :: Resource | ||
usersResource = Resource | ||
{ name = "User" | ||
, endpoint = URI [relativeUri|/Users|] | ||
, schema = User20 | ||
} | ||
|
||
groupsResource :: Resource | ||
groupsResource = Resource | ||
{ name = "Group" | ||
, endpoint = URI [relativeUri|/Groups|] | ||
, schema = Group20 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.