auth

Paddy 2015-05-17 Parent:581c60f8dd23 Child:bdb83e88e1da

169:37a42585660e Go to Latest

auth/authd/server.go

Create interfaces for login verification flow. We needed an interface that we could use to say "send the email to verify the user's login" so that we could verify the emails we have are actually valid. This implements an NSQ version that sends an email_verification event. We'll get listener implementations that pull these messages off NSQ and actually send the emails. This also implements, for testing purposes, a version that just echoes the Login Value and the Verification code to stdout.

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 config.JWTPrivateKey = []byte(`secret`)
39 err := config.Init()
40 if err != nil {
41 log.Fatal(err)
42 }
43 context, err := auth.NewContext(config)
44 if err != nil {
45 panic(err)
46 }
47 err = context.CreateScopes([]auth.Scope{
48 {ID: "testscope", Name: "Test Scope"},
49 })
50 if err != nil && err != auth.ErrScopeAlreadyExists {
51 log.Fatal(err)
52 }
54 router := mux.NewRouter()
55 auth.RegisterOAuth2(router, context)
56 auth.RegisterSessionHandlers(router, context)
57 auth.RegisterProfileHandlers(router, context)
58 auth.RegisterClientHandlers(router, context)
59 http.Handle("/", router)
60 log.Fatal(http.ListenAndServe(":8080", nil))
61 }