auth

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

154:5f670aba87b4 Go to Latest

auth/authd/server.go

Implement a session store in postgres. Write the postgres implementation of our sessionStore type. Write the SQL statements to initialize the database for us. Include the postgres implementation of our sessionStore type in our sessionStore tests when the appropriate environment variable is passed.

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