auth

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

104:bc77a315f823 Go to Latest

auth/authd/server.go

Add request helpers. Fix a typo in the requestErrConflict constant. Create a response type that is used to build responses before sending them down the wire. Create vars for a few common types of error responses that never change. Create a negotiate middleware function that will respond with a 406 error if the client requests an encoding that we can't support. Create an encode helper that determines the requested encoding and uses it to send the data down the wire. Move our wrap middleware from the oauth2.go file to the request.go file, where it's more likely to be looked for.

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@100 8 "code.secondbit.org/auth"
paddy@100 9
paddy@100 10 "github.com/gorilla/mux"
paddy@100 11 )
paddy@100 12
paddy@100 13 func main() {
paddy@100 14 store := auth.NewMemstore()
paddy@100 15 config := auth.Config{
paddy@100 16 ClientStore: store,
paddy@100 17 AuthCodeStore: store,
paddy@100 18 ProfileStore: store,
paddy@100 19 TokenStore: store,
paddy@100 20 SessionStore: store,
paddy@100 21 Template: template.Must(template.New("base").ParseGlob("./templates/*.gotmpl")),
paddy@100 22 LoginURI: "/login",
paddy@100 23 }
paddy@100 24 context, err := auth.NewContext(config)
paddy@100 25 if err != nil {
paddy@100 26 panic(err)
paddy@100 27 }
paddy@100 28
paddy@100 29 router := mux.NewRouter()
paddy@100 30 auth.RegisterOAuth2(router, context)
paddy@100 31 auth.RegisterSessionHandlers(router, context)
paddy@100 32 http.Handle("/", router)
paddy@100 33 log.Fatal(http.ListenAndServe(":8080", nil))
paddy@100 34 }