File tree 2 files changed +36
-1
lines changed
2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -6,5 +6,37 @@ open Suave.Web // for config
6
6
open Suave.Filters
7
7
open Suave.Writers
8
8
open Suave.Operators
9
+ open Suave.Redirection
9
10
10
11
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)
Original file line number Diff line number Diff line change @@ -14,7 +14,10 @@ module Program =
14
14
let app =
15
15
choose
16
16
[ GET >=> choose
17
- [ path " /" >=> helloWorld]]
17
+ [ path " /" >=> helloWorld
18
+ path " /auth" >=> startAuth]
19
+ POST >=> choose
20
+ [ path " /auth/handshake" >=> authComplete]]
18
21
19
22
let port =
20
23
match System.UInt16.TryParse( System.Environment.GetEnvironmentVariable( " PORT" )) with
You can’t perform that action at this time.
0 commit comments