auth

Paddy 2015-04-11 Parent:202e991accc2 Child:0ff23f3a4ede

158:3223a8e679db Go to Latest

auth/authd/server.go

Remove concept of usernames. We really have no reason to use usernames, and they're complicating things more than they need to. We're going to keep logins the same, because we want to be able to support OAuth2/OpenID/whatever logins in the future, and keeping a type associated with those logins is probably for the best.

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