首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用最重要的client4 go驱动程序登录个人访问令牌的官方方式是什么?

使用最重要的client4 go驱动程序登录个人访问令牌的官方方式是什么?
EN

Stack Overflow用户
提问于 2018-08-10 23:26:18
回答 1查看 729关注 0票数 0

我们在运行两台最重要的服务器。

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

我们在client4 go驱动程序中使用用户名和密码登录,但是过一段时间就会超时。似乎无法使用个人访问令牌与官方客户端4驱动程序登录。

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

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

最接近的工作方式是使用用户名和密码登录,然后通过client.MockSession设置身份验证令牌,测试失败。

使用最重要的client4 go驱动程序登录个人访问令牌的官方方式是什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-12 03:45:30

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

代码语言:javascript
复制
    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
    }

上下文。

代码语言:javascript
复制
/* 
    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
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51795115

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档