Revert "Remove sensitive information from LoggedUser endpoint"

This reverts commit e91a1f3e6f.
This commit is contained in:
Marcos Lilljedahl
2017-11-12 21:28:38 -03:00
parent 0541165b70
commit 3dee0d3f0b
2 changed files with 17 additions and 1 deletions

View File

@@ -68,7 +68,7 @@ func Register(extend HandlerExtender) {
http.ServeFile(rw, r, "./www/landing.html") http.ServeFile(rw, r, "./www/landing.html")
}).Methods("GET") }).Methods("GET")
corsRouter.HandleFunc("/users/me", GetUser).Methods("GET") corsRouter.HandleFunc("/users/me", LoggedInUser).Methods("GET")
r.HandleFunc("/users/{userId:^(?me)}", GetUser).Methods("GET") r.HandleFunc("/users/{userId:^(?me)}", GetUser).Methods("GET")
r.HandleFunc("/oauth/providers", ListProviders).Methods("GET") r.HandleFunc("/oauth/providers", ListProviders).Methods("GET")
r.HandleFunc("/oauth/providers/{provider}/login", Login).Methods("GET") r.HandleFunc("/oauth/providers/{provider}/login", Login).Methods("GET")

View File

@@ -17,6 +17,22 @@ import (
"github.com/twinj/uuid" "github.com/twinj/uuid"
) )
func LoggedInUser(rw http.ResponseWriter, req *http.Request) {
cookie, err := ReadCookie(req)
if err != nil {
log.Println("Cannot read cookie")
rw.WriteHeader(http.StatusUnauthorized)
return
}
user, err := core.UserGet(cookie.Id)
if err != nil {
log.Printf("Couldn't get user with id %s. Got: %v\n", cookie.Id, err)
rw.WriteHeader(http.StatusUnauthorized)
return
}
json.NewEncoder(rw).Encode(user)
}
func ListProviders(rw http.ResponseWriter, req *http.Request) { func ListProviders(rw http.ResponseWriter, req *http.Request) {
providers := []string{} providers := []string{}
for name, _ := range config.Providers { for name, _ := range config.Providers {