mirror of
https://github.com/42wim/matterbridge.git
synced 2024-11-15 08:29:25 +01:00
This commit is contained in:
parent
d379118772
commit
107969c09a
@ -273,7 +273,7 @@ func (b *Bmattermost) handleMatterHook(messages chan *config.Message) {
|
|||||||
func (b *Bmattermost) apiLogin() error {
|
func (b *Bmattermost) apiLogin() error {
|
||||||
password := b.GetString("Password")
|
password := b.GetString("Password")
|
||||||
if b.GetString("Token") != "" {
|
if b.GetString("Token") != "" {
|
||||||
password = "MMAUTHTOKEN=" + b.GetString("Token")
|
password = "token=" + b.GetString("Token")
|
||||||
}
|
}
|
||||||
|
|
||||||
b.mc = matterclient.New(b.GetString("Login"), password, b.GetString("Team"), b.GetString("Server"))
|
b.mc = matterclient.New(b.GetString("Login"), password, b.GetString("Team"), b.GetString("Server"))
|
||||||
|
@ -26,6 +26,8 @@ type Credentials struct {
|
|||||||
Login string
|
Login string
|
||||||
Team string
|
Team string
|
||||||
Pass string
|
Pass string
|
||||||
|
Token string
|
||||||
|
CookieToken bool
|
||||||
Server string
|
Server string
|
||||||
NoTLS bool
|
NoTLS bool
|
||||||
SkipTLSVerify 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.Transport = &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: m.SkipTLSVerify}, Proxy: http.ProxyFromEnvironment}
|
||||||
m.Client.HttpClient.Timeout = time.Second * 10
|
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 {
|
for {
|
||||||
d := b.Duration()
|
d := b.Duration()
|
||||||
// bogus call to get the serverversion
|
// bogus call to get the serverversion
|
||||||
@ -144,22 +163,22 @@ func (m *MMClient) Login() error {
|
|||||||
var logmsg = "trying login"
|
var logmsg = "trying login"
|
||||||
for {
|
for {
|
||||||
m.log.Debugf("%s %s %s %s", logmsg, m.Credentials.Team, m.Credentials.Login, m.Credentials.Server)
|
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) {
|
if m.Credentials.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]
|
|
||||||
m.Client.AuthType = model.HEADER_BEARER
|
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("")
|
m.User, resp = m.Client.GetMe("")
|
||||||
if resp.Error != nil {
|
if resp.Error != nil {
|
||||||
return resp.Error
|
return resp.Error
|
||||||
}
|
}
|
||||||
if m.User == nil {
|
if m.User == nil {
|
||||||
m.log.Errorf("LOGIN TOKEN: %s is invalid", m.Credentials.Pass)
|
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 {
|
} else {
|
||||||
m.User, resp = m.Client.Login(m.Credentials.Login, m.Credentials.Pass)
|
m.User, resp = m.Client.Login(m.Credentials.Login, m.Credentials.Pass)
|
||||||
|
Loading…
Reference in New Issue
Block a user