Skip to content

Commit e3d6971

Browse files
authored
Merge pull request #137 from unisoncomputing/cp/add-org-client
Add org API client
2 parents 50e33f6 + 29fb701 commit e3d6971

File tree

51 files changed

+1415
-205
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1415
-205
lines changed

hie.yaml

Lines changed: 0 additions & 97 deletions
This file was deleted.

package.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ dependencies:
110110
- servant
111111
- servant-auth
112112
- servant-client
113+
- servant-client-core
113114
- servant-server
114115
- servant-conduit
115116
- serialise

share-api.cabal

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ library
187187
Share.Web.Share.Tickets.Impl
188188
Share.Web.Share.Tickets.Types
189189
Share.Web.Share.Types
190+
Share.Web.Share.Users.API
190191
Share.Web.Support.API
191192
Share.Web.Support.Impl
192193
Share.Web.Support.Types
@@ -310,6 +311,7 @@ library
310311
, servant
311312
, servant-auth
312313
, servant-client
314+
, servant-client-core
313315
, servant-conduit
314316
, servant-server
315317
, share-auth
@@ -466,6 +468,7 @@ executable share-api
466468
, servant
467469
, servant-auth
468470
, servant-client
471+
, servant-client-core
469472
, servant-conduit
470473
, servant-server
471474
, share-api

share-auth/src/Share/OAuth/Session.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ where
2929
import Control.Applicative
3030
import Control.Monad.Random
3131
import Control.Monad.Trans.Maybe (MaybeT (..))
32+
import Crypto.JWT qualified as JWT
3233
import Data.Aeson
3334
import Data.Aeson qualified as Aeson
3435
import Data.Binary
@@ -46,6 +47,7 @@ import Network.HTTP.Types qualified as Network
4647
import Network.URI
4748
import Network.Wai qualified as Wai
4849
import Servant
50+
import Servant.Client.Core.Auth qualified as ServantAuth
4951
import Servant.Server.Experimental.Auth qualified as ServantAuth
5052
import Share.JWT
5153
import Share.OAuth.Types
@@ -63,6 +65,8 @@ type AuthenticatedSession = Servant.AuthProtect "require-session"
6365

6466
type instance ServantAuth.AuthServerData (Servant.AuthProtect "require-session") = Session
6567

68+
type instance ServantAuth.AuthClientData (Servant.AuthProtect "require-session") = JWT.SignedJWT
69+
6670
-- | Requires a valid session cookie to be present in the request,
6771
-- provides the authenticated user's user-id as an argument to the handler
6872
--
@@ -71,6 +75,8 @@ type AuthenticatedUserId = Servant.AuthProtect "require-user-id"
7175

7276
type instance ServantAuth.AuthServerData (AuthProtect "require-user-id") = UserId
7377

78+
type instance ServantAuth.AuthClientData (AuthProtect "require-user-id") = JWT.SignedJWT
79+
7480
-- | Used for endpoints with optional auth.
7581
-- Provides 'Just' the session if a valid session cookie is present in the request,
7682
-- otherwise provides 'Nothing'.
@@ -80,13 +86,17 @@ type MaybeAuthenticatedSession = Servant.AuthProtect "maybe-session"
8086

8187
type instance ServantAuth.AuthServerData (AuthProtect "maybe-session") = Maybe Session
8288

89+
type instance ServantAuth.AuthClientData (AuthProtect "maybe-session") = Maybe JWT.SignedJWT
90+
8391
-- | Used for endpoints with optional auth.
8492
-- Provides 'Just' the user ID if a valid session cookie is present in the request,
8593
-- otherwise provides 'Nothing'.
8694
type MaybeAuthenticatedUserId = Servant.AuthProtect "maybe-user-id"
8795

8896
type instance ServantAuth.AuthServerData (AuthProtect "maybe-user-id") = Maybe UserId
8997

98+
type instance ServantAuth.AuthClientData (AuthProtect "maybe-user-id") = Maybe JWT.SignedJWT
99+
90100
-- | An additional check to perform on a session. Returns True if valid, False otherwise.
91101
type SessionCheck = (Session -> Handler Bool)
92102

share-auth/src/Share/OAuth/Types.hs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ import Data.Text (Text)
4242
import Data.Text qualified as Text
4343
import Data.Time (NominalDiffTime)
4444
import Data.UUID (UUID)
45+
import GHC.TypeLits (Symbol, symbolVal)
46+
import Hasql.Interpolate qualified as Hasql
47+
import Servant
4548
import Share.JWT.Types
4649
import Share.OAuth.Scopes
4750
import Share.Utils.Binary (JSONBinary (..))
4851
import Share.Utils.IDs
4952
import Share.Utils.Show (Censored (..))
5053
import Share.Utils.URI (URIParam)
51-
import GHC.TypeLits (Symbol, symbolVal)
52-
import Hasql.Interpolate qualified as Hasql
53-
import Servant
5454
import Web.FormUrlEncoded (FromForm (..), ToForm (..))
5555
import Web.FormUrlEncoded qualified as Form
5656

@@ -117,10 +117,17 @@ newtype PKCEVerifier = PKCEVerifier Text
117117
deriving (Show) via Text
118118

119119
data ResponseType = ResponseTypeCode
120+
deriving stock (Show, Eq, Ord)
120121

121122
instance ToJSON ResponseType where
122123
toJSON ResponseTypeCode = Aeson.String "code"
123124

125+
instance FromJSON ResponseType where
126+
parseJSON = Aeson.withText "ResponseType" $ \txt -> do
127+
case Text.toLower txt of
128+
"code" -> pure ResponseTypeCode
129+
_ -> fail $ "Unsupported response_type: " <> Text.unpack txt
130+
124131
instance ToHttpApiData ResponseType where
125132
toQueryParam = \case
126133
ResponseTypeCode -> "code"

share-client/LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2024, Unison Computing, public benefit corp and contributors
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

share-client/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# share-client

share-client/Setup.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Distribution.Simple
2+
3+
main = defaultMain

share-client/package.yaml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: share-client
2+
version: 0.1.0.0
3+
github: "unisoncomputing/share-api"
4+
author: "Unison Computing"
5+
maintainer: "Unison Computing"
6+
copyright: "2024 Unison Computing"
7+
8+
extra-source-files:
9+
- README.md
10+
11+
# Metadata used when publishing your package
12+
# synopsis: Short description of your package
13+
# category: Web
14+
15+
# To avoid duplicated efforts in documentation and dealing with the
16+
# complications of embedding Haddock markup inside cabal files, it is
17+
# common to point users to the README.md file.
18+
description: Please see the README on GitHub at <https://github.com/unisoncomputing/share-api#readme>
19+
20+
ghc-options:
21+
- -Wall
22+
- -Werror
23+
- -Wno-name-shadowing
24+
- -Wno-type-defaults
25+
- -Wno-missing-pattern-synonym-signatures
26+
- -fprint-expanded-synonyms
27+
- -fwrite-ide-info
28+
- -O2
29+
- -funbox-strict-fields
30+
31+
default-extensions:
32+
- ApplicativeDo
33+
- BangPatterns
34+
- BlockArguments
35+
- DeriveFunctor
36+
- DeriveGeneric
37+
- DeriveFoldable
38+
- DeriveTraversable
39+
- DerivingStrategies
40+
- DerivingVia
41+
- DoAndIfThenElse
42+
- FlexibleContexts
43+
- FlexibleInstances
44+
- GeneralizedNewtypeDeriving
45+
- InstanceSigs
46+
- LambdaCase
47+
- MultiParamTypeClasses
48+
- NamedFieldPuns
49+
- OverloadedStrings
50+
- PatternSynonyms
51+
- RankNTypes
52+
- ScopedTypeVariables
53+
- TupleSections
54+
- TypeApplications
55+
- ViewPatterns
56+
- QuasiQuotes
57+
- BlockArguments
58+
- QuasiQuotes
59+
- ImportQualifiedPost
60+
61+
dependencies:
62+
- base >= 4.7 && < 5
63+
- jose
64+
- servant
65+
- servant-client
66+
- servant-client-core
67+
- share-auth
68+
- share-api
69+
- text
70+
- wai
71+
72+
library:
73+
source-dirs: src

share-client/share-client.cabal

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
cabal-version: 1.12
2+
3+
-- This file has been generated from package.yaml by hpack version 0.37.0.
4+
--
5+
-- see: https://github.com/sol/hpack
6+
7+
name: share-client
8+
version: 0.1.0.0
9+
description: Please see the README on GitHub at <https://github.com/unisoncomputing/share-api#readme>
10+
homepage: https://github.com/unisoncomputing/share-api#readme
11+
bug-reports: https://github.com/unisoncomputing/share-api/issues
12+
author: Unison Computing
13+
maintainer: Unison Computing
14+
copyright: 2024 Unison Computing
15+
license: MIT
16+
license-file: LICENSE
17+
build-type: Simple
18+
extra-source-files:
19+
README.md
20+
21+
source-repository head
22+
type: git
23+
location: https://github.com/unisoncomputing/share-api
24+
25+
library
26+
exposed-modules:
27+
Share.Client.Orgs
28+
Share.Client.Users
29+
Share.Client.Utils
30+
other-modules:
31+
Paths_share_client
32+
hs-source-dirs:
33+
src
34+
default-extensions:
35+
ApplicativeDo
36+
BangPatterns
37+
BlockArguments
38+
DeriveFunctor
39+
DeriveGeneric
40+
DeriveFoldable
41+
DeriveTraversable
42+
DerivingStrategies
43+
DerivingVia
44+
DoAndIfThenElse
45+
FlexibleContexts
46+
FlexibleInstances
47+
GeneralizedNewtypeDeriving
48+
InstanceSigs
49+
LambdaCase
50+
MultiParamTypeClasses
51+
NamedFieldPuns
52+
OverloadedStrings
53+
PatternSynonyms
54+
RankNTypes
55+
ScopedTypeVariables
56+
TupleSections
57+
TypeApplications
58+
ViewPatterns
59+
QuasiQuotes
60+
BlockArguments
61+
QuasiQuotes
62+
ImportQualifiedPost
63+
ghc-options: -Wall -Werror -Wno-name-shadowing -Wno-type-defaults -Wno-missing-pattern-synonym-signatures -fprint-expanded-synonyms -fwrite-ide-info -O2 -funbox-strict-fields
64+
build-depends:
65+
base >=4.7 && <5
66+
, jose
67+
, servant
68+
, servant-client
69+
, servant-client-core
70+
, share-api
71+
, share-auth
72+
, text
73+
, wai
74+
default-language: Haskell2010

0 commit comments

Comments
 (0)