gpt4 book ai didi

go - 对于 mattermost,使用 client4 go 驱动程序使用个人访问 token 登录的官方方式是什么?

转载 作者:数据小太阳 更新时间:2023-10-29 03:22:15 25 4
gpt4 key购买 nike

我们正在运行两个 mattermost 服务器。

我们有一个使用 https://github.com/Vaelor/python-mattermost-driver 登录的 python 进程将个人访问 token 与社区 Python 驱动程序一起使用。此过程有一个不会超时的 session ,这是使用个人访问 token 登录的好处之一。 https://docs.mattermost.com/developer/personal-access-tokens.html .

我们使用 client4 go 驱动程序的用户名和密码登录,这有效,但一段时间后超时。似乎无法使用个人访问 token 登录官方客户端 4 驱动程序。

Mattermost Client4 代码的文档位于 https://godoc.org/github.com/mattermost/platform/model#Client

client4 的源位于 https://github.com/mattermost/mattermost-server/blob/master/model/client4.go

看起来最接近可行的是使用用户名和密码登录,然后通过 client.MockSession 设置身份验证 token ,但测试失败。

对于 mattermost,使用 client4 go 驱动程序使用个人访问 token 登录的官方方式是什么?

最佳答案

关键是登录、设置个人访问 token 和调用 client.GetMe。在查看 python 驱动程序源代码后,这一点变得很清楚。相关片段是。

    fmt.Println("LoginAsTheBotUser", "Using personal access token")
client.AuthToken = mattermost_personal_access_token
client.AuthType = model.HEADER_TOKEN
if user, resp := client.GetMe(""); resp.Error != nil {
println("There was a problem logging into the Mattermost server. Are you sure the access token is valid?")
PrintError(resp.Error)
} else {
fmt.Println(client)
botUser = user
result = true
}

上下文。

/* 
mattermost_user_email, mattermost_user_password and mattermost_personal_access_token
are globals set from reading a .env file on startup
*/
func LoginAsTheBotUser() bool {
fmt.Println("LoginAsTheBotUser")
fmt.Println("LoginAsTheBotUser", time.Now())
var result bool = false
if mattermost_personal_access_token == "" {
fmt.Println("LoginAsTheBotUser", "Getting access token from login with username and password")
if user, resp := client.Login(mattermost_user_email, mattermost_user_password); resp.Error != nil {
println("There was a problem logging into the Mattermost server. Are you sure ran the setup steps from the README.md?")
PrintError(resp.Error)
} else {
fmt.Println(client)
botUser = user
result = true
}
} else {
fmt.Println("LoginAsTheBotUser", "Using personal access token")
client.AuthToken = mattermost_personal_access_token
client.AuthType = model.HEADER_TOKEN
if user, resp := client.GetMe(""); resp.Error != nil {
//if user, resp := client.Login(mattermost_personal_access_token); resp.Error != nil {
println("There was a problem logging into the Mattermost server. Are you sure the access token is valid?")
PrintError(resp.Error)
} else {
fmt.Println(client)
botUser = user
result = true
}
}
fmt.Println("LoginAsTheBotUser", time.Now())
fmt.Println("LoginAsTheBotUser")
return result
}

关于go - 对于 mattermost,使用 client4 go 驱动程序使用个人访问 token 登录的官方方式是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51795115/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com