add token auth tests
This commit is contained in:
parent
92f0f035a9
commit
10ecb3058f
2 changed files with 9 additions and 6 deletions
|
@ -12,9 +12,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type TokenPayload struct {
|
type TokenPayload struct {
|
||||||
access_token string
|
AccessToken string `json:"access_token"`
|
||||||
token_type string
|
TokenType string `json:"token_type"`
|
||||||
expires_in int
|
ExpiresIn int `json:"expires_in"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func Protected(next http.Handler, method string, userStore auth.UserStore, login string) http.Handler {
|
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)
|
token, err := userStore.GrantToken(user, password, ttl)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
token := TokenPayload{
|
token := TokenPayload{
|
||||||
access_token: token,
|
AccessToken: token,
|
||||||
token_type: "bearer",
|
TokenType: "bearer",
|
||||||
expires_in: ttl,
|
ExpiresIn: ttl,
|
||||||
}
|
}
|
||||||
util.AddContextValue(req, "token", token)
|
util.AddContextValue(req, "token", token)
|
||||||
renderer.JSON("token").ServeHTTP(w, req)
|
renderer.JSON("token").ServeHTTP(w, req)
|
||||||
|
|
|
@ -49,6 +49,9 @@ func TestMain(m *testing.M) {
|
||||||
|
|
||||||
rtr.Post("/login", middleware.Authorize("/", udb, "/login?tryagain=1", 120))
|
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(
|
rtr.Get("/", middleware.Protected(
|
||||||
renderer.Template(
|
renderer.Template(
|
||||||
"testData/templates/test.html"), http.MethodGet, udb, "/login"))
|
"testData/templates/test.html"), http.MethodGet, udb, "/login"))
|
||||||
|
|
Loading…
Reference in a new issue