Description
BasicAuth doesn't work.
How to reproduce
This is demo code, main.go
package main
import (
"github.com/gin-gonic/gin"
)
func main() {
router := gin.Default()
authorized := router.Group("/", gin.BasicAuth(gin.Accounts{
"user": "pass",
}))
authorized.Static("/", string("./"))
router.Run()
}
Also add an index.html
at root directory to test access, same level with main.go
.
then run the app:
go run main.go
Expectations
- When accessing on browser at
http://localhost:8080/index.html
, it expects to show the Basic Auth request dialog to authenticate.
Actual result
Browser responds ERR_TOO_MANY_RETRIES
, and server logs return tons of these responses:
[GIN] 2022/06/18 - 00:12:48 | 401 | 5.167µs | ::1 | GET "/"
[GIN] 2022/06/18 - 00:12:48 | 401 | 6.708µs | ::1 | GET "/"
[GIN] 2022/06/18 - 00:12:48 | 401 | 5.709µs | ::1 | GET "/"
[GIN] 2022/06/18 - 00:12:48 | 401 | 5.167µs | ::1 | GET "/"
[GIN] 2022/06/18 - 00:12:48 | 401 | 2.417µs | ::1 | GET "/"
[GIN] 2022/06/18 - 00:12:48 | 401 | 4.166µs | ::1 | GET "/"
Environment
- go version: go1.18.3 darwin/arm64
- gin version (or commit ref): github.com/gin-gonic/gin v1.8.1
- operating system: MacOS 12.4 / MacBook Pro (16-inch, 2021) Apple M1 Max
Additional Info
the code works fine if removing the BasicAuth
middleware
authorized := router.Group("/")
Comment From: petehouston
Ooops, some crazy site data persists in my development machine, it actually works.