auth
100:d03786cbf3ae Browse Files
Add authd. Start adding our server implementation. Right now, it's very proof-of-concept stage and will almost certainly be entirely rewritten, but it gets a server up and running.
authd/server.go authd/templates/simple.gotmpl
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/authd/server.go Sun Dec 14 12:10:57 2014 -0500 1.3 @@ -0,0 +1,34 @@ 1.4 +package main 1.5 + 1.6 +import ( 1.7 + "html/template" 1.8 + "log" 1.9 + "net/http" 1.10 + 1.11 + "code.secondbit.org/auth" 1.12 + 1.13 + "github.com/gorilla/mux" 1.14 +) 1.15 + 1.16 +func main() { 1.17 + store := auth.NewMemstore() 1.18 + config := auth.Config{ 1.19 + ClientStore: store, 1.20 + AuthCodeStore: store, 1.21 + ProfileStore: store, 1.22 + TokenStore: store, 1.23 + SessionStore: store, 1.24 + Template: template.Must(template.New("base").ParseGlob("./templates/*.gotmpl")), 1.25 + LoginURI: "/login", 1.26 + } 1.27 + context, err := auth.NewContext(config) 1.28 + if err != nil { 1.29 + panic(err) 1.30 + } 1.31 + 1.32 + router := mux.NewRouter() 1.33 + auth.RegisterOAuth2(router, context) 1.34 + auth.RegisterSessionHandlers(router, context) 1.35 + http.Handle("/", router) 1.36 + log.Fatal(http.ListenAndServe(":8080", nil)) 1.37 +}
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/authd/templates/simple.gotmpl Sun Dec 14 12:10:57 2014 -0500 2.3 @@ -0,0 +1,17 @@ 2.4 +{{ define "login" }}<html> 2.5 + <head> 2.6 + <title>Log in</title> 2.7 + </head> 2.8 + <body> 2.9 + <h1>Please log into your account</h1>{{ if .errors }} 2.10 + <h2>Errors:</h2> 2.11 + <ul>{{ range .errors }} 2.12 + <li>{{ . }}</li> 2.13 + </ul>{{ end }}{{ end }} 2.14 + <form method="POST"> 2.15 + <p>Username: <input type="text" name="login"></p> 2.16 + <p>Password: <input type="password" name="passphrase"></p> 2.17 + <p><input type="submit"></p> 2.18 + </form> 2.19 + </body> 2.20 +</html>{{ end }}