aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--middleware/middleware.go12
-rw-r--r--quartzgun_test.go3
2 files changed, 9 insertions, 6 deletions
diff --git a/middleware/middleware.go b/middleware/middleware.go
index 046f5c9..30dd4cc 100644
--- a/middleware/middleware.go
+++ b/middleware/middleware.go
@@ -12,9 +12,9 @@ import (
)
type TokenPayload struct {
- access_token string
- token_type string
- expires_in int
+ AccessToken string `json:"access_token"`
+ TokenType string `json:"token_type"`
+ ExpiresIn int `json:"expires_in"`
}
func Protected(next http.Handler, method string, userStore auth.UserStore, login string) http.Handler {
@@ -91,9 +91,9 @@ func Provision(userStore auth.UserStore, ttl int) http.Handler {
token, err := userStore.GrantToken(user, password, ttl)
if err == nil {
token := TokenPayload{
- access_token: token,
- token_type: "bearer",
- expires_in: ttl,
+ AccessToken: token,
+ TokenType: "bearer",
+ ExpiresIn: ttl,
}
util.AddContextValue(req, "token", token)
renderer.JSON("token").ServeHTTP(w, req)
diff --git a/quartzgun_test.go b/quartzgun_test.go
index ca7b2be..b555d90 100644
--- a/quartzgun_test.go
+++ b/quartzgun_test.go
@@ -49,6 +49,9 @@ func TestMain(m *testing.M) {
rtr.Post("/login", middleware.Authorize("/", udb, "/login?tryagain=1", 120))
+ rtr.Post("/provision", middleware.Provision(udb, 60))
+ rtr.Get("/protected", middleware.Validate(renderer.Template("testData/templates/test.html"), udb, map[string]string{}))
+
rtr.Get("/", middleware.Protected(
renderer.Template(
"testData/templates/test.html"), http.MethodGet, udb, "/login"))