auth

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

166:c45b946abe78 Go to Latest

auth/authd/server.go

Implement a GetProfileHandler. Create a Handler that will allow us to return details about a Profile. Right now, you only get a single Profile at a time, which is problematic, because it will lead to N+1 requests. But we have no reason to retrieve anyone _else_'s Profile, so it's not like you need to be fetching any Profile other than your own. Also, this requires a Token issued for the Profile in question, which means you're limited to one Profile per request, anyways. Future avenues for exploration may be an admin Token granting access to many Profiles, the unspecified service flow for accessing the API, or simply accepting that name, join date, last active date, and ID are "public information".

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 }