Skip to content

Commit b64e1f1

Browse files
committed
Starting down the OAuth route
1 parent b6ce1f0 commit b64e1f1

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

Diff for: pages2docs/Actions.fs

+32
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,37 @@ open Suave.Web // for config
66
open Suave.Filters
77
open Suave.Writers
88
open Suave.Operators
9+
open Suave.Redirection
910

1011
let helloWorld = OK "<html><body><h1>Welcome to Pages2Docs!</h1></body></html>\n"
12+
13+
let clientId =
14+
match Some(System.Environment.GetEnvironmentVariable("GH_CLIENT_ID")) with
15+
| Some key -> key
16+
| None -> "MISSING"
17+
18+
let redirectUrl =
19+
match Some(System.Environment.GetEnvironmentVariable("GH_REDIRECT_URL")) with
20+
| Some key -> key
21+
| None -> "https://localhost:5000/auth/complete"
22+
23+
24+
let scope = "public_repo"
25+
let state = System.Guid.NewGuid().ToString()
26+
27+
let startAuth : WebPart =
28+
let p = "https://github.com/login/oauth/authorize"
29+
let q = (sprintf "?client_id=%s&&redirect_uri=%s&scope=%s&state=%s" clientId redirectUrl scope state)
30+
redirect p
31+
32+
let authComplete : WebPart = request (fun req ->
33+
let clientId = match (req.formData "client_id") with
34+
| Choice1Of2 t -> t
35+
| Choice2Of2 t -> "MISSING"
36+
let clientSecret = match (req.formData "client_secret") with
37+
| Choice1Of2 t -> t
38+
| Choice2Of2 t -> "MISSING"
39+
let code = match (req.formData "code") with
40+
| Choice1Of2 t -> t
41+
| Choice2Of2 t -> "MISSING"
42+
OK code)

Diff for: pages2docs/Program.fs

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ module Program =
1414
let app =
1515
choose
1616
[ GET >=> choose
17-
[ path "/" >=> helloWorld]]
17+
[ path "/" >=> helloWorld
18+
path "/auth" >=> startAuth]
19+
POST >=> choose
20+
[ path "/auth/handshake" >=> authComplete]]
1821

1922
let port =
2023
match System.UInt16.TryParse(System.Environment.GetEnvironmentVariable("PORT")) with

0 commit comments

Comments
 (0)