Skip to content

Commit

Permalink
split into packages, add ms-auth and ms-azure-api
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Zocca committed Jun 19, 2023
1 parent 40659c0 commit 03417bf
Show file tree
Hide file tree
Showing 34 changed files with 356 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/.cabal-sandbox/
/cabal.sandbox.config
/.stack-work/
.DS_Store
11 changes: 11 additions & 0 deletions ms-auth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Changelog for `ms-auth`

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to the
[Haskell Package Versioning Policy](https://pvp.haskell.org/).

## Unreleased

## 0.1.0.0 - YYYY-MM-DD
File renamed without changes.
File renamed without changes.
52 changes: 52 additions & 0 deletions ms-auth/ms-auth.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: ms-auth
version: 0.1.0.0
synopsis: Microsoft Authentication API
description: Bindings to the Microsoft Authentication API / Azure ActiveDirectory (AAD) for building applications that use either Delegated or App-only permissions. Helper functions are provided for building OAuth2 authentication flows and keep tokens transactionally secure and up to date.
homepage: https://github.com/unfoldml/ms-auth
license: BSD3
license-file: LICENSE
author: Marco Zocca
maintainer: [email protected]
copyright: 2023 Marco Zocca, UnfoldML
category: Web
build-type: Simple
extra-source-files: README.md
CHANGELOG.md
cabal-version: >=1.10
tested-with: GHC == 9.2.8

library
default-language: Haskell2010
hs-source-dirs: src
exposed-modules: Network.OAuth2.JWT
Network.OAuth2.Session
Network.OAuth2.Provider.AzureAD
build-depends: base >= 4.7 && < 5
, aeson
, bytestring
, containers
, hoauth2 == 2.6.0
, http-client
, http-types
, jwt
, scientific
, scotty
, text
, time
, transformers
, uri-bytestring
, validation-micro
, unliftio
ghc-options: -Wall
-Wcompat
-Widentities
-Wincomplete-record-updates
-Wincomplete-uni-patterns
-Wmissing-export-lists
-Wmissing-home-modules
-Wpartial-fields
-Wredundant-constraints

source-repository head
type: git
location: https://github.com/unfoldml/ms-auth
File renamed without changes.
File renamed without changes.
File renamed without changes.
36 changes: 36 additions & 0 deletions ms-auth/stack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
resolver:
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/20/26.yaml

packages:
- .

extra-deps:
- validation-micro-1.0.0.0
# - git: https://github.com/commercialhaskell/stack.git
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a

# extra-deps: []

# Override default flag values for local packages and extra-deps
# flags: {}

# Extra package databases containing global packages
# extra-package-dbs: []

# Control whether we use the GHC we find on the path
# system-ghc: true
#
# Require a specific version of Stack, using version ranges
# require-stack-version: -any # Default
# require-stack-version: ">=2.9"
#
# Override the architecture used by Stack, especially useful on Windows
# arch: i386
# arch: x86_64
#
# Extra directories used by Stack for building
# extra-include-dirs: [/path/to/dir]
# extra-lib-dirs: [/path/to/dir]
#
# Allow a newer minor version of GHC than the snapshot specifies
# compiler-check: newer-minor
File renamed without changes.
11 changes: 11 additions & 0 deletions ms-azure-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Changelog for `ms-azure-api`

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to the
[Haskell Package Versioning Policy](https://pvp.haskell.org/).

## Unreleased

## 0.1.0.0 - YYYY-MM-DD
30 changes: 30 additions & 0 deletions ms-azure-api/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Copyright Author name here (c) 2023

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* Neither the name of Author name here nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5 changes: 5 additions & 0 deletions ms-azure-api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# ms-azure-api

[![Build Status](https://travis-ci.org/unfoldml/ms-azure-api.png)](https://travis-ci.org/unfoldml/ms-azure-api)

TODO Description.
2 changes: 2 additions & 0 deletions ms-azure-api/Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain
47 changes: 47 additions & 0 deletions ms-azure-api/ms-azure-api.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: ms-azure-api
version: 0.1.0.0
-- synopsis:
-- description:
homepage: https://github.com/unfoldml/ms-azure-api
license: BSD3
license-file: LICENSE
author: Marco Zocca
maintainer: [email protected]
copyright: 2023 Marco Zocca
category: Web
build-type: Simple
extra-source-files: README.md
CHANGELOG.md
cabal-version: >=1.10
tested-with: GHC == 7.10.2

library
default-language: Haskell2010
hs-source-dirs: src
exposed-modules: MSAzureAPI.Internal.Common
build-depends: base >= 4.7 && < 5
, aeson
, bytestring
, containers
, hoauth2 == 2.6.0
, http-types
, modern-uri
, req
, scientific
, text
, time >= 1.8
, transformers >= 0.5
, unliftio
ghc-options: -Wall
-Wcompat
-Wno-unused-imports
default-extensions: OverloadedStrings
DeriveGeneric
DeriveFunctor
DerivingStrategies
LambdaCase


source-repository head
type: git
location: https://github.com/unfoldml/ms-azure-api
1 change: 1 addition & 0 deletions ms-azure-api/src/MSAzureAPI.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module MSAzureAPI where
78 changes: 78 additions & 0 deletions ms-azure-api/src/MSAzureAPI/Internal/Common.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{-# LANGUAGE DataKinds #-}
{-# options_ghc -Wno-unused-imports #-}
-- | Common functions for the MS Azure API
--
module MSAzureAPI.Internal.Common where

import Control.Monad.IO.Class (MonadIO(..))
import Data.Proxy (Proxy)
import GHC.Generics (Generic(..))

import Data.List (sort, sortBy, stripPrefix, uncons)
import Data.Maybe (listToMaybe, fromMaybe)
-- import Data.Ord (comparing)
import Data.Char (toLower)

-- aeson
import qualified Data.Aeson as A (ToJSON(..), FromJSON(..), genericParseJSON, defaultOptions, Options(..), withObject, withText, (.:), (.:?), object, (.=), Key, Value, camelTo2)
-- bytestring
import qualified Data.ByteString as BS (ByteString)
import qualified Data.ByteString.Char8 as BS8 (pack, unpack)
import qualified Data.ByteString.Lazy as LBS (ByteString)
import qualified Data.ByteString.Lazy.Char8 as LBS8 (pack, unpack, putStrLn)
-- hoauth2
import Network.OAuth.OAuth2 (OAuth2Token(..))
import Network.OAuth.OAuth2.Internal (AccessToken(..), ExchangeToken(..), RefreshToken(..), OAuth2Error, IdToken(..))
-- modern-uri
-- import Text.URI (URI, mkURI)
-- req
import Network.HTTP.Req (Req, runReq, HttpException(..), defaultHttpConfig, req, Option, (=:), GET(..), POST(..), Url, Scheme(..), useHttpsURI, https, (/:), ReqBodyJson(..), NoReqBody(..), oAuth2Bearer, HttpResponse(..), jsonResponse, JsonResponse, lbsResponse, LbsResponse, bsResponse, BsResponse, responseBody)
-- text
import Data.Text (Text, pack, unpack)



-- | Data plane e.g for FileREST API

-- | Control plane
msAzureManagementReqConfig :: AccessToken -> [Text] -> (Url 'Https, Option 'Https)
msAzureManagementReqConfig (AccessToken ttok) uriRest = (url, os)
where
url = (https "management.azure.com") //: uriRest
os = oAuth2Bearer $ BS8.pack (unpack ttok)

(//:) :: Url scheme -> [Text] -> Url scheme
(//:) = foldl (/:)


-- * aeson

-- | a collection of items with key @value@
data Collection a = Collection {
cValue :: [a]
} deriving (Eq, Show, Generic)
instance A.FromJSON a => A.FromJSON (Collection a) where
parseJSON = A.genericParseJSON (aesonOptions "c")

-- | drop the prefix and lowercase first character
--
-- e.g. @userDisplayName@ @->@ @displayName@
aesonOptions :: String -- ^ record prefix
-> A.Options
aesonOptions pfx = A.defaultOptions { A.fieldLabelModifier = recordName pfx }

-- | drop the prefix and lowercase first character
recordName :: String -- ^ record name prefix
-> String -- ^ JSON field name
-> String
recordName pf str = case uncons $ dropPrefix pf str of
Just (c, cs) -> toLower c : cs
_ -> error "record name cannot be empty"

-- | Drops the given prefix from a list.
-- It returns the original sequence if the sequence doesn't start with the given prefix.
--
-- > dropPrefix "Mr. " "Mr. Men" == "Men"
-- > dropPrefix "Mr. " "Dr. Men" == "Dr. Men"
dropPrefix :: Eq a => [a] -> [a] -> [a]
dropPrefix a b = fromMaybe b $ stripPrefix a b
39 changes: 39 additions & 0 deletions ms-azure-api/stack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
resolver:
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/20/26.yaml

packages:
- .
# Dependency packages to be pulled from upstream that are not in the resolver.
# These entries can reference officially published versions as well as
# forks / in-progress versions pinned to a git hash. For example:
#
# extra-deps:
# - acme-missiles-0.3
# - git: https://github.com/commercialhaskell/stack.git
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
#
# extra-deps: []

# Override default flag values for local packages and extra-deps
# flags: {}

# Extra package databases containing global packages
# extra-package-dbs: []

# Control whether we use the GHC we find on the path
# system-ghc: true
#
# Require a specific version of Stack, using version ranges
# require-stack-version: -any # Default
# require-stack-version: ">=2.9"
#
# Override the architecture used by Stack, especially useful on Windows
# arch: i386
# arch: x86_64
#
# Extra directories used by Stack for building
# extra-include-dirs: [/path/to/dir]
# extra-lib-dirs: [/path/to/dir]
#
# Allow a newer minor version of GHC than the snapshot specifies
# compiler-check: newer-minor
1 change: 1 addition & 0 deletions ms-azure-api/test/Spec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{-# OPTIONS_GHC -F -pgmF hspec-discover #-}
8 changes: 7 additions & 1 deletion CHANGELOG.md → ms-graph-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ and this project adheres to the

## Unreleased

MSGraphAPI.ChangeNotifications.Subscription :

## 1.0.0.0

MSGraphAPI.ChangeNotifications.Subscription

== Breaking changes:

Moved the Network/* module hierarchy to the @ms-auth@ package shared with @ms-azure-api@


## 0.6.0.0
Expand Down
30 changes: 30 additions & 0 deletions ms-graph-api/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Copyright Author name here (c) 2023

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* Neither the name of Author name here nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
File renamed without changes.
2 changes: 2 additions & 0 deletions ms-graph-api/Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain
Loading

0 comments on commit 03417bf

Please sign in to comment.