Go,基本访问认证

huangapple go评论98阅读模式
英文:

Go, basic access authentication

问题

谷歌Go支持解码基本访问认证调用吗?我如何从http.Request中获取用户名和密码?

英文:

Does Google Go support decoding of basic access authentication calls? How do I get the username and password from the http.Request?

答案1

得分: 3

Go在浏览器中以URL形式输入基本身份验证时似乎无法拦截,但它允许从其他调用它的应用程序中获取它。

例如,使用一个简单的Python代码来进行HTTP JSON RPC

from jsonrpc import ServiceProxy
access = ServiceProxy("http://user:pass@127.0.0.1:8080/")
print access.getinfo()

在Go中调用:

// r *http.Request
r.Header["Authorization"]

会得到以下字符串:

[Basic dXNlcjpwYXNz]

以及

dXNlcjpwYXNz

经过Base-64解码后得到

user:pass

因此,在Go中进行一些基本身份验证是可能的,尽管可能不是一个可靠的方法。

英文:

Go does not seem to intercept basic authentication when it is typed as an URL in a browser, but it does allow one to get it from some other applications calling it.

For example, using a simple Python code for HTTP JSON RPC:

from jsonrpc import ServiceProxy
access = ServiceProxy("http://user:pass@127.0.0.1:8080/")
print access.getinfo()

And in Go calling:

// r *http.Request
r.Header["Authorization"]

One gets this string:

[Basic dXNlcjpwYXNz]

And

dXNlcjpwYXNz

Base-64 decoded gives

user:pass

So some basic authentication in Go is possible, although it might not be something one can rely on.

答案2

得分: 0

似乎没有办法获取用户提供的身份验证信息,但是您可以通过调用SetBasicAuth来提供有效的用户名和密码进行HTTP基本身份验证。

英文:

There seems to be no way to get the user-provided authentication info, but you can provide the valid username and password for HTTP Basic Authentication by calling SetBasicAuth.

huangapple
  • 本文由 发表于 2012年1月20日 06:52:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/8934546.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定