auth

Paddy 2014-12-14 Parent:d03786cbf3ae Child:c03b5eb3179e

106:d442523df640 Go to Latest

auth/authd/server.go

Init Config, add profile handlers, and add grant template. Call config.Init() before attempting to use it. Register our profile handlers with the router. Define a simple get_grant template for the authorization grant endpoint.

History
1 package main
3 import (
4 "html/template"
5 "log"
6 "net/http"
8 "code.secondbit.org/auth"
10 "github.com/gorilla/mux"
11 )
13 func main() {
14 store := auth.NewMemstore()
15 config := auth.Config{
16 ClientStore: store,
17 AuthCodeStore: store,
18 ProfileStore: store,
19 TokenStore: store,
20 SessionStore: store,
21 Template: template.Must(template.New("base").ParseGlob("./templates/*.gotmpl")),
22 LoginURI: "/login",
23 }
24 err := config.Init()
25 if err != nil {
26 log.Fatal(err)
27 }
28 context, err := auth.NewContext(config)
29 if err != nil {
30 panic(err)
31 }
33 router := mux.NewRouter()
34 auth.RegisterOAuth2(router, context)
35 auth.RegisterSessionHandlers(router, context)
36 auth.RegisterProfileHandlers(router, context)
37 http.Handle("/", router)
38 log.Fatal(http.ListenAndServe(":8080", nil))
39 }