使用 Lua 编写一个 Nginx 认证模块
|
写一个处理器,来弹出一个基本的验证窗体不是很难,但是Go没有完美的文档,所以我必须自己一点点寻猎。其实非常简单,最终,这里就是HTTP基本验证的Go代码:
func handler(w http.ResponseWriter,r *http.Request) {
""
?{
w.Header().Set("WWW-Authenticate" "The kingdom of Stavros" `)
|
w.Write([]byte("401 Unauthorizedn" ))
|
else
?fmt.Printf(
"Authenticated user %v.n"
token := getToken()
setTokenCookie(w,token) |
"<html><head><script>location.reload()</script></head></html>"
)
} |