auth

Paddy 2015-04-07 Parent:de5e09680f6b Child:202e991accc2

156:2809016184f6 Go to Latest

auth/authd/server.go

Implement postgres version of authCodeStore. Create an authCodeStore that keeps data in Postgres. Again, we run into the problem where Scopes can't be stored in Postgres arrays, as discussed in 762953f6a7f2. I wish we could do better, but for now, it will suffice. We also added the postgres authCodeStore to our slice of authCodeStores to test when the correct environment variables are present. Wrote initialization SQL for the tables required by the postgres authCodeStore. Added SQL to the SQL script that empties our database, to properly empty our new tables.

History
paddy@100 1 package main
paddy@100 2
paddy@100 3 import (
paddy@100 4 "html/template"
paddy@100 5 "log"
paddy@100 6 "net/http"
paddy@100 7
paddy@107 8 "code.secondbit.org/auth.hg"
paddy@100 9 "github.com/gorilla/mux"
paddy@100 10 )
paddy@100 11
paddy@100 12 func main() {
paddy@151 13 log.SetFlags(log.LstdFlags | log.Llongfile)
paddy@149 14 p, err := auth.NewPostgres("dbname=testdb sslmode=disable")
paddy@149 15 if err != nil {
paddy@149 16 panic(err)
paddy@149 17 }
paddy@100 18 store := auth.NewMemstore()
paddy@149 19 if err != nil {
paddy@149 20 panic(err)
paddy@149 21 }
paddy@100 22 config := auth.Config{
paddy@151 23 ClientStore: &p,
paddy@100 24 AuthCodeStore: store,
paddy@149 25 ProfileStore: &p,
paddy@100 26 TokenStore: store,
paddy@100 27 SessionStore: store,
paddy@152 28 ScopeStore: &p,
paddy@100 29 Template: template.Must(template.New("base").ParseGlob("./templates/*.gotmpl")),
paddy@100 30 LoginURI: "/login",
paddy@100 31 }
paddy@149 32 err = config.Init()
paddy@106 33 if err != nil {
paddy@106 34 log.Fatal(err)
paddy@106 35 }
paddy@100 36 context, err := auth.NewContext(config)
paddy@100 37 if err != nil {
paddy@100 38 panic(err)
paddy@100 39 }
paddy@149 40 err = context.CreateScopes([]auth.Scope{
paddy@149 41 {ID: "testscope", Name: "Test Scope"},
paddy@149 42 })
paddy@152 43 if err != nil {
paddy@152 44 panic(err)
paddy@152 45 }
paddy@100 46
paddy@100 47 router := mux.NewRouter()
paddy@100 48 auth.RegisterOAuth2(router, context)
paddy@100 49 auth.RegisterSessionHandlers(router, context)
paddy@106 50 auth.RegisterProfileHandlers(router, context)
paddy@108 51 auth.RegisterClientHandlers(router, context)
paddy@100 52 http.Handle("/", router)
paddy@100 53 log.Fatal(http.ListenAndServe(":8080", nil))
paddy@100 54 }