如何使用Golang站点实现基本的auth?因此,当某人访问某个页面时,他们的浏览器会提示他们登录。
发布于 2016-03-23 20:35:10
为了强制用户进行身份验证/使用户浏览器中的基本提示出现,您将发送报头WWW-Authenticate : Basic ream="mydomain"
因此,如果您有一个名为http.ResponseWriter的w,您可以
w.Header().Set("WWW-Authenticate", `Basic realm="mydomain"`)这将导致浏览器打开所指的提示符。
发布于 2018-05-30 15:46:03
您还可以使用回声实验室项目,它提供基本的Auth中间件:
e.Use(middleware.BasicAuth(func(username, password string, c echo.Context) (bool, error) {
// check username and password for a match here
}))使用上面的代码保护具有基本身份验证的任何路由组。
https://stackoverflow.com/questions/36187853
复制相似问题