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 {
|
||||
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)
|
||||
|
|
|
@ -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"))
|
||||
|
|
Loading…
Reference in a new issue