File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Expand file tree Collapse file tree 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
66open Suave.Filters
77open Suave.Writers
88open Suave.Operators
9+ open Suave.Redirection
910
1011let 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 =
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
You can’t perform that action at this time.
0 commit comments