auth

Paddy 2015-01-18 Parent:2e4b5722eed0 Child:8267e1c8bcd1

123:0a1e16b9c141 Go to Latest

auth/authd/server.go

Refactor verifyClient, implement refresh tokens. Refactor verifyClient into verifyClient and getClientAuth. We moved verifyClient out of each of the GrantType's validation functions and into the access token endpoint, where it will be called before the GrantType's validation function. Yay, less code repetition. And seeing as we always want to verify the client, that seems like a good way to prevent things like 118a69954621 from happening. This did, however, force us to add an AllowsPublic property to the GrantType, so the token endpoint knows whether or not a public Client is valid for any given GrantType. We also implemented the refresh token grant type, which required adding ClientID and RefreshRevoked as properties on the Token type. We need ClientID because we need to constrain refresh tokens to the client that issued them. We also should probably keep track of which tokens belong to which clients, just as a general rule of thumb. RefreshRevoked had to be created, next to Revoked, because the AccessToken could be revoked and the RefreshToken still valid, or vice versa. Notably, when you issue a new refresh token, the old one is revoked, but the access token is still valid. It remains to be seen whether this is a good way to track things or not. The number of duplicated properties lead me to believe our type is not a great representation of the underlying concepts.

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