jax*_*orm 3 go hashicorp-vault
我正在尝试使用Vault Golang包来使用API进行身份验证.
我创建了一个新客户端,然后可以设置我的令牌:
client, err := api.NewClient(&api.Config{Address: vaultAddr, HttpClient: httpClient})
if err != nil {
return nil, errors.Wrap(err, "could not create vault client")
}
client.SetToken(token)
Run Code Online (Sandbox Code Playgroud)
这很好,但我想使用其他一个auth方法(LDAP,Userpass等)对API进行身份验证
这甚至可能吗?如何使用API检索令牌?
我想我可以使用net/http来使用API调用来检索令牌,但有没有任何方法可以用另一种方式实际验证?
最终,我设法解决了这个问题.这不是很明显,但有道理.
Vault有一个用于写入数据的通用写入方法.您可以通过简单地构建URL并向该端点发送PUT请求来利用它来执行API登录
看起来有点像这样:
// create a vault client
client, err := api.NewClient(&api.Config{Address: url, HttpClient: httpClient})
if err != nil {
panic(err)
}
// to pass the password
options := map[string]interface{}{
"password": password,
}
// the login path
// this is configurable, change userpass to ldap etc
path := fmt.Sprintf("auth/userpass/login/%s", username)
// PUT call to get a token
secret, err := client.Logical().Write(path, options)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2029 次 |
| 最近记录: |