-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split into packages, add ms-auth and ms-azure-api
- Loading branch information
Marco Zocca
committed
Jun 19, 2023
1 parent
40659c0
commit 03417bf
Showing
34 changed files
with
356 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
/.cabal-sandbox/ | ||
/cabal.sandbox.config | ||
/.stack-work/ | ||
.DS_Store |
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,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.
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 @@ | ||
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.
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,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.
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,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 |
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,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. |
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,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. |
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,2 @@ | ||
import Distribution.Simple | ||
main = defaultMain |
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,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 |
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 @@ | ||
module MSAzureAPI where |
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,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 |
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,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 |
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 @@ | ||
{-# OPTIONS_GHC -F -pgmF hspec-discover #-} |
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,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.
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,2 @@ | ||
import Distribution.Simple | ||
main = defaultMain |
Oops, something went wrong.