使用Golang的HTTP基本身份验证 [英] HTTP Basic Auth with Golang

查看:872
本文介绍了使用Golang的HTTP基本身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过Golang网站实现基本身份验证?这样,当某人访问某个页面时,他们的浏览器会提示他们登录.

How do I implement basic auth with a Golang site? So that when someone visits a page they will be prompted by their browser with a login.

推荐答案

为了强制用户进行身份验证/使用户浏览器中出现基本身份验证提示,请发送标头WWW-Authenticate : Basic ream="mydomain"

In order to force a user to authenticate/make that basic auth prompt in the users browser appear you send the header WWW-Authenticate : Basic ream="mydomain"

因此,如果您有一个名为whttp.ResponseWriter,则可以

So if you have a http.ResponseWriter called w, you can do

 w.Header().Set("WWW-Authenticate", `Basic realm="mydomain"`)

这将导致浏览器打开您所指的提示.

Which will cause the browser to open the prompt you're referring to.

这篇关于使用Golang的HTTP基本身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆