summaryrefslogtreecommitdiffstats
path: root/matterclient
diff options
context:
space:
mode:
authorWim <wim@42.be>2018-10-26 16:47:56 +0200
committerGitHub <noreply@github.com>2018-10-26 16:47:56 +0200
commit107969c09a044cbce185a50a63cf58e0281eafc3 (patch)
treed7c196d57f00d21cf0ae72c30a326371cbe238c1 /matterclient
parentd379118772aa68d0b35bb5a98b5600dc81a89197 (diff)
downloadmatterbridge-msglm-107969c09a044cbce185a50a63cf58e0281eafc3.tar.gz
matterbridge-msglm-107969c09a044cbce185a50a63cf58e0281eafc3.tar.bz2
matterbridge-msglm-107969c09a044cbce185a50a63cf58e0281eafc3.zip
Split up cookie token and personal token (mattermost). Fixes #530 (#540)
Diffstat (limited to 'matterclient')
-rw-r--r--matterclient/matterclient.go37
1 files changed, 28 insertions, 9 deletions
diff --git a/matterclient/matterclient.go b/matterclient/matterclient.go
index 117a2fe9..6ea99507 100644
--- a/matterclient/matterclient.go
+++ b/matterclient/matterclient.go
@@ -26,6 +26,8 @@ type Credentials struct {
Login string
Team string
Pass string
+ Token string
+ CookieToken bool
Server string
NoTLS bool
SkipTLSVerify bool
@@ -117,6 +119,23 @@ func (m *MMClient) Login() error {
m.Client.HttpClient.Transport = &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: m.SkipTLSVerify}, Proxy: http.ProxyFromEnvironment}
m.Client.HttpClient.Timeout = time.Second * 10
+ if strings.Contains(m.Credentials.Pass, model.SESSION_COOKIE_TOKEN) {
+ token := strings.Split(m.Credentials.Pass, model.SESSION_COOKIE_TOKEN+"=")
+ if len(token) != 2 {
+ return errors.New("incorrect MMAUTHTOKEN. valid input is MMAUTHTOKEN=yourtoken")
+ }
+ m.Credentials.Token = token[1]
+ m.Credentials.CookieToken = true
+ }
+
+ if strings.Contains(m.Credentials.Pass, "token=") {
+ token := strings.Split(m.Credentials.Pass, "token=")
+ if len(token) != 2 {
+ return errors.New("incorrect personal token. valid input is token=yourtoken")
+ }
+ m.Credentials.Token = token[1]
+ }
+
for {
d := b.Duration()
// bogus call to get the serverversion
@@ -144,22 +163,22 @@ func (m *MMClient) Login() error {
var logmsg = "trying login"
for {
m.log.Debugf("%s %s %s %s", logmsg, m.Credentials.Team, m.Credentials.Login, m.Credentials.Server)
- if strings.Contains(m.Credentials.Pass, model.SESSION_COOKIE_TOKEN) {
- m.log.Debugf(logmsg + " with token")
- token := strings.Split(m.Credentials.Pass, model.SESSION_COOKIE_TOKEN+"=")
- if len(token) != 2 {
- return errors.New("incorrect MMAUTHTOKEN. valid input is MMAUTHTOKEN=yourtoken")
- }
- m.Client.HttpClient.Jar = m.createCookieJar(token[1])
- m.Client.AuthToken = token[1]
+ if m.Credentials.Token != "" {
m.Client.AuthType = model.HEADER_BEARER
+ m.Client.AuthToken = m.Credentials.Token
+ if m.Credentials.CookieToken {
+ m.log.Debugf(logmsg + " with cookie (MMAUTH) token")
+ m.Client.HttpClient.Jar = m.createCookieJar(m.Credentials.Token)
+ } else {
+ m.log.Debugf(logmsg + " with personal token")
+ }
m.User, resp = m.Client.GetMe("")
if resp.Error != nil {
return resp.Error
}
if m.User == nil {
m.log.Errorf("LOGIN TOKEN: %s is invalid", m.Credentials.Pass)
- return errors.New("invalid " + model.SESSION_COOKIE_TOKEN)
+ return errors.New("invalid token")
}
} else {
m.User, resp = m.Client.Login(m.Credentials.Login, m.Credentials.Pass)