diff --git a/ms-graph-api-test/CHANGELOG.md b/ms-graph-api-test/CHANGELOG.md new file mode 100644 index 0000000..76b5432 --- /dev/null +++ b/ms-graph-api-test/CHANGELOG.md @@ -0,0 +1,11 @@ +# Changelog for `ms-graph-api-test` + +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 diff --git a/ms-graph-api-test/LICENSE b/ms-graph-api-test/LICENSE new file mode 100644 index 0000000..c5b6c16 --- /dev/null +++ b/ms-graph-api-test/LICENSE @@ -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. diff --git a/ms-graph-api-test/README.md b/ms-graph-api-test/README.md new file mode 100644 index 0000000..1d5b69b --- /dev/null +++ b/ms-graph-api-test/README.md @@ -0,0 +1,5 @@ +# ms-graph-api-test + +[![Build Status](https://travis-ci.org/githubuser/ms-graph-api-test.png)](https://travis-ci.org/githubuser/ms-graph-api-test) + +TODO Description. diff --git a/ms-graph-api-test/Setup.hs b/ms-graph-api-test/Setup.hs new file mode 100644 index 0000000..9a994af --- /dev/null +++ b/ms-graph-api-test/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/ms-graph-api-test/app/Main.hs b/ms-graph-api-test/app/Main.hs new file mode 100644 index 0000000..489e939 --- /dev/null +++ b/ms-graph-api-test/app/Main.hs @@ -0,0 +1,109 @@ +{-# LANGUAGE DataKinds #-} +{-# language OverloadedStrings #-} +{-# language QuasiQuotes #-} +{-# options_ghc -Wno-unused-imports #-} +module Main (main) where + +import Control.Monad.IO.Class (MonadIO(..)) + +-- hoauth2 +import Network.OAuth.OAuth2 (OAuth2Token(..)) +import Network.OAuth2.Experiment (IdpApplication, GrantTypeFlow(..)) +-- http-client +import Network.HTTP.Client (Manager, newManager) +-- http-client-tls +import Network.HTTP.Client.TLS (tlsManagerSettings) +-- req +import Network.HTTP.Req (runReq, defaultHttpConfig, httpConfigAltManager) +-- scotty +import Web.Scotty.Trans (ScottyT, scottyT, get, html, RoutePattern, middleware) +-- text +import qualified Data.Text as T (unpack) +import qualified Data.Text.Lazy as TL (Text, pack) +-- transformers +import Control.Monad.Trans.Reader (runReaderT) +-- unliftio +import UnliftIO.STM (STM, newTVarIO) +-- uri-bytestring +import URI.ByteString.QQ (uri) +-- wai-extra +import Network.Wai.Middleware.RequestLogger (logStdoutDev) + +import qualified MSGraphAPI.Users.User as MSG (getMe, User(..)) +import Network.OAuth2.Provider.AzureAD (OAuthCfg(..), azureOAuthADApp, AzureAD) +import Network.OAuth2.Session (Tokens, newTokens, tokensToList, withAADUser, loginEndpoint, replyEndpoint, UserSub, Scotty, Action) + + +main :: IO () +main = server + +server :: MonadIO m => m () +server = do + ts <- newTokens + mgr <- liftIO $ newManager tlsManagerSettings + let + runR r = runReaderT r ts + scottyT 3000 runR $ do + middleware logStdoutDev + loginEndpoint idpApp "/oauth/login" + replyEndpoint idpApp ts mgr "/oauth/reply" + allTokensEndpoint ts "/tokens" + currentUsersEndpoint ts (Just mgr) "/me" + +-- currentUserEndpoint :: MonadIO m => +-- Tokens UserSub OAuth2Token +-- -> RoutePattern -> Scotty m () +-- currentUserEndpoint ts pth = get pth $ withAADUser ts "/oauth/login" $ \oat -> do +-- let +-- t = accessToken oat +-- u <- runReq defaultHttpConfig $ MSG.getMe t +-- let +-- uname = MSG.uDisplayName u +-- h = TL.pack $ unwords ["", "