From b64e1f1bb6e1fe8ac4af4a1099b1a75e1b7c2762 Mon Sep 17 00:00:00 2001 From: Dru Sellers Date: Thu, 18 Aug 2016 07:09:48 -0500 Subject: [PATCH] Starting down the OAuth route --- pages2docs/Actions.fs | 32 ++++++++++++++++++++++++++++++++ pages2docs/Program.fs | 5 ++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/pages2docs/Actions.fs b/pages2docs/Actions.fs index cab594c..905f87c 100644 --- a/pages2docs/Actions.fs +++ b/pages2docs/Actions.fs @@ -6,5 +6,37 @@ open Suave.Web // for config open Suave.Filters open Suave.Writers open Suave.Operators +open Suave.Redirection let helloWorld = OK "

Welcome to Pages2Docs!

\n" + +let clientId = + match Some(System.Environment.GetEnvironmentVariable("GH_CLIENT_ID")) with + | Some key -> key + | None -> "MISSING" + +let redirectUrl = + match Some(System.Environment.GetEnvironmentVariable("GH_REDIRECT_URL")) with + | Some key -> key + | None -> "https://localhost:5000/auth/complete" + + +let scope = "public_repo" +let state = System.Guid.NewGuid().ToString() + +let startAuth : WebPart = + let p = "https://github.com/login/oauth/authorize" + let q = (sprintf "?client_id=%s&&redirect_uri=%s&scope=%s&state=%s" clientId redirectUrl scope state) + redirect p + +let authComplete : WebPart = request (fun req -> + let clientId = match (req.formData "client_id") with + | Choice1Of2 t -> t + | Choice2Of2 t -> "MISSING" + let clientSecret = match (req.formData "client_secret") with + | Choice1Of2 t -> t + | Choice2Of2 t -> "MISSING" + let code = match (req.formData "code") with + | Choice1Of2 t -> t + | Choice2Of2 t -> "MISSING" + OK code) diff --git a/pages2docs/Program.fs b/pages2docs/Program.fs index c3a97d9..1e5ce1e 100644 --- a/pages2docs/Program.fs +++ b/pages2docs/Program.fs @@ -14,7 +14,10 @@ module Program = let app = choose [ GET >=> choose - [ path "/" >=> helloWorld]] + [ path "/" >=> helloWorld + path "/auth" >=> startAuth] + POST >=> choose + [ path "/auth/handshake" >=> authComplete]] let port = match System.UInt16.TryParse(System.Environment.GetEnvironmentVariable("PORT")) with