42wim / matterircd

Connect to your mattermost or slack using your IRC-client of choice.
MIT License
294 stars 60 forks source link

Gitlab auth: can receive mattermost messages but it seems that my messages are not sent #370

Closed mlemerre closed 3 years ago

mlemerre commented 3 years ago

Hi,

I use matterircd to connect to a mattermost instance, and while I can receive the messages just fine, sending them does no appear to work.

Specifically, I am using:

Thanks for matterircd!

Matthieu

42wim commented 3 years ago

can you run with --debug ? Do you see "... with cookie (MMAUTH) token ..." somewhere?

mlemerre commented 3 years ago

Here is the debug log when I tried to write something

DEBU[2021-01-14T01:17:37+01:00] B: "<- PRIVMSG name :b" module=matterircd DEBU[2021-01-14T01:17:37+01:00] flushing buffer: &irc.Message{Prefix:(irc.Prefix)(nil), Command:"PRIVMSG", Params:[]string{"name"}, Trailing:"b", EmptyTrailing:false} module=matterircd DEBU[2021-01-14T01:17:37+01:00] Executed &irc.Message{Prefix:(irc.Prefix)(nil), Command:"PRIVMSG", Params:[]string{"name"}, Trailing:"b", EmptyTrailing:false} module=matterircd [2021-01-14T01:17:43+01:00] DEBUG matterclient: WsReceiver response: &model.WebSocketResponse{Status:"OK", SeqReply:3, Data:map[string]interface {}{"node_id":"", "server_time":1.610583463638e+12, "text":"pong", "version":"5.28.0"}, Error:(model.AppError)(nil)} [2021-01-14T01:17:43+01:00] DEBUG matterclient: getting response: &model.WebSocketResponse{Status:"OK", SeqReply:3, Data:map[string]interface {}{"node_id":"", "server_time":1.610583463638e+12, "text":"pong", "version":"5.28.0"}, Error:(model.AppError)(nil)} DEBU[2021-01-14T01:17:44+01:00] <- PING 1610583464 module=matterircd DEBU[2021-01-14T01:17:44+01:00] -> :matterircd PONG matterircd :1610583464 module=matterircd DEBU[2021-01-14T01:17:44+01:00] Executed &irc.Message{Prefix:(*irc.Prefix)(nil), Command:"PING", Params:[]string{"1610583464"}, Trailing:"1610583464", EmptyTrailing:false}

module=matterircd [2021-01-14T01:18:13+01:00] DEBUG matterclient: posting lastview "hzo..." [2021-01-14T01:18:13+01:00] DEBUG matterclient: posting lastview "hur..." [2021-01-14T01:18:13+01:00] ERROR matterclient: ChannelView update for hzo... failed: : Invalid or expired session, please login again., [2021-01-14T01:18:13+01:00] ERROR matterclient: ChannelView update for hur... failed: : Invalid or expired session, please login again., and this is the MMAUTH part: [2021-01-14T01:16:12+01:00] DEBUG matterclient: trying login team lemerre server [2021-01-14T01:16:12+01:00] DEBUG matterclient: trying login with cookie (MMAUTH) token [2021-01-14T01:16:12+01:00] INFO matterclient: found 54 users in team team [2021-01-14T01:16:12+01:00] DEBUG matterclient: initUser(): found our team team (id: 7z5...) [2021-01-14T01:16:13+01:00] INFO matterclient: found 36 users in team team2 [2021-01-14T01:16:13+01:00] DEBUG matterclient: WsClient: making connection: wss://server [2021-01-14T01:16:13+01:00] DEBUG matterclient: WsClient: connected [2021-01-14T01:16:13+01:00] DEBUG matterclient: starting wsreceiver [2021-01-14T01:16:13+01:00] DEBUG matterclient: executing OnWsConnect() INFO[2021-01-14T01:16:13+01:00] login succeeded [2021-01-14T01:16:13+01:00] DEBUG matterclient: starting WsReceiver DEBU[2021-01-14T01:16:13+01:00] in addUsersToChannels() module=matterircd On Wed, Jan 13, 2021 at 11:46 PM Wim wrote: > can you run with --debug ? > Do you see "... with cookie (MMAUTH) token ..." somewhere? > > — > You are receiving this because you authored the thread. > Reply to this email directly, view it on GitHub > , > or unsubscribe > > . >
42wim commented 3 years ago

I don't have such a setup so I can't test this myself, but it's strange that login succeeds and then the other stuff fails.

Can you ask the admin if they see something about this in the mattermost server logs?

mlemerre commented 3 years ago

Yes, I asked and he told me that he had 10 times this:

"2001:861:4284:e290:b7e4:96:9e1c:e771 - - [15/Jan/2021:00:03:25 +0100] "POST /api/v4/channels/members/9u5kx3nb8fn3umiotqjzdf7k7o/view HTTP/1.1" 401 186 "" "Go-http-client/1.1" -" 401 => "No access token provided"

It seems to me that matterircd tries to send a regular token instead of an MMAUTH token when sending data, or something like this

On Thu, Jan 14, 2021 at 11:22 PM Wim notifications@github.com wrote:

I don't have such a setup so I can't test this myself, but it's strange that login succeeds and then the other stuff fails.

Can you ask the admin if they see something about this in the mattermost server logs?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/42wim/matterircd/issues/370#issuecomment-760513012, or unsubscribe https://github.com/notifications/unsubscribe-auth/AATOY3XPX3LXRVLIEHTH6XTSZ5VA7ANCNFSM4V7JRH6Q .

mlemerre commented 3 years ago

My administrator gave me a personal token which solves the problem for me, but the problem remains.

hloeung commented 3 years ago

@mlemerre so after you see all those "invalid or expired session" errors, can you log into the Mattermost web UI and type something? Does it come through to matterircd?

I'm just wonder if it's just that the session token has expired. Could probably reproduce this with:

curl -i -d '{"login_id":"someone@nowhere.com","password":"thisisabadpassword"}' http://localhost:8065/api/v4/users/login

Then grabbing the provided Token and using that with matterircd to connect.

yourealwaysbe commented 3 years ago

I am having the same issue. I can receive messages that i type into the web client, but cannot send messages via matterircd. Here is a debug log. The message "this is a test" goes from browser client to matterircd and succeeds. The message "but i can't reply" fails to go from matterircd to the web client.

[2021-06-23T10:46:26+01:00] DEBUG matterclient: WsReceiver event: &model.WebSocketEvent{Event:"posted", Data:map[string]interface {}{"channel_display_name":"Off-Topic", "channel_name":"off-topic", "channel_type":"O", "post":"{\"id\":\"<id>\",\"create_at\":1624441586911,\"update_at\":1624441586911,\"edit_at\":0,\"delete_at\":0,\"is_pinned\":false,\"user_id\":\"<userid>\",\"channel_id\":\"<channelid>\",\"root_id\":\"\",\"parent_id\":\"\",\"original_id\":\"\",\"message\":\"This is a test :)\",\"type\":\"\",\"props\":{\"disable_group_highlight\":true},\"hashtags\":\"\",\"pending_post_id\":\"i3dfkdnju7rkjc94hr4ipdhqtc:1624441586749\",\"reply_count\":0,\"last_reply_at\":0,\"participants\":null,\"metadata\":{}}", "sender_name":"@<username>", "set_online":true, "team_id":"<team>"}, Broadcast:(*model.WebsocketBroadcast)(0xc000264740), Sequence:4, precomputedJSON:(*model.precomputedWebSocketEventJSON)(nil)}
DEBU[2021-06-23T10:46:26+01:00] MMUser WsReceiver: &model.WebSocketEvent{Event:"posted", Data:map[string]interface {}{"channel_display_name":"Off-Topic", "channel_name":"off-topic", "channel_type":"O", "post":"{\"id\":\"<id>\",\"create_at\":1624441586911,\"update_at\":1624441586911,\"edit_at\":0,\"delete_at\":0,\"is_pinned\":false,\"user_id\":\"<userid>\",\"channel_id\":\"<channelid>\",\"root_id\":\"\",\"parent_id\":\"\",\"original_id\":\"\",\"message\":\"This is a test :)\",\"type\":\"\",\"props\":{\"disable_group_highlight\":true},\"hashtags\":\"\",\"pending_post_id\":\"<id>:1624441586749\",\"reply_count\":0,\"last_reply_at\":0,\"participants\":null,\"metadata\":{}}", "sender_name":"@<username>", "set_online":true, "team_id":"<teamid>"}, Broadcast:(*model.WebsocketBroadcast)(0xc000264740), Sequence:4, precomputedJSON:(*model.precomputedWebSocketEventJSON)(nil)} 
DEBU[2021-06-23T10:46:26+01:00] handleWsActionPost() receiving userid <userid> 
DEBU[2021-06-23T10:46:26+01:00] handleWsActionPost() user <userid> sent This is a test :) 
DEBU[2021-06-23T10:46:26+01:00] &model.Post{Id:"<id>", CreateAt:1624441586911, UpdateAt:1624441586911, EditAt:0, DeleteAt:0, IsPinned:false, UserId:"<userid>", ChannelId:"<channelid>", RootId:"", ParentId:"", OriginalId:"", Message:"This is a test :)", MessageSource:"", Type:"", propsMu:sync.RWMutex{w:sync.Mutex{state:0, sema:0x0}, writerSem:0x0, readerSem:0x0, readerCount:0, readerWait:0}, Props:model.StringInterface{"disable_group_highlight":true}, Hashtags:"", Filenames:model.StringArray(nil), FileIds:model.StringArray(nil), PendingPostId:"<id>:1624441586749", HasReactions:false, ReplyCount:0, Metadata:(*model.PostMetadata)(0xc000176e00)} 
DEBU[2021-06-23T10:46:26+01:00] in handleWsMessage0                          
DEBU[2021-06-23T10:46:26+01:00] in handleChannelMessageEvent                  module=matterircd
DEBU[2021-06-23T10:46:26+01:00] -> :matt!matt@matt PRIVMSG #off-topic :This is a test :)  module=matterircd
[2021-06-23T10:46:26+01:00] DEBUG matterclient: WsReceiver event: &model.WebSocketEvent{Event:"channel_viewed", Data:map[string]interface {}{"channel_id":"<channelid>"}, Broadcast:(*model.WebsocketBroadcast)(0xc00054a340), Sequence:5, precomputedJSON:(*model.precomputedWebSocketEventJSON)(nil)}
DEBU[2021-06-23T10:46:26+01:00] MMUser WsReceiver: &model.WebSocketEvent{Event:"channel_viewed", Data:map[string]interface {}{"channel_id":"<channelid>"}, Broadcast:(*model.WebsocketBroadcast)(0xc00054a340), Sequence:5, precomputedJSON:(*model.precomputedWebSocketEventJSON)(nil)} 
DEBU[2021-06-23T10:46:27+01:00] in handleWsMessage0                          
[2021-06-23T10:46:29+01:00] DEBUG matterclient: posting lastview "<idthing>"
[2021-06-23T10:46:29+01:00] ERROR matterclient: ChannelView update for <idthing> failed: : Invalid or expired session, please login again., 
ERRO[2021-06-23T10:46:29+01:00] updateLastViewed failed: : Invalid or expired session, please login again.,  
DEBU[2021-06-23T10:46:47+01:00] B: "<- PRIVMSG #off-topic :But i can't reply"  module=matterircd
DEBU[2021-06-23T10:46:47+01:00] flushing buffer: &irc.Message{Prefix:(*irc.Prefix)(nil), Command:"PRIVMSG", Params:[]string{"#off-topic"}, Trailing:"But i can't reply", EmptyTrailing:false}  module=matterircd
DEBU[2021-06-23T10:46:47+01:00] -> :matt!matt@localhost PRIVMSG mattermost :msg: But i can't reply could not be send: : Invalid or expired session, please login again.,  module=matterircd
DEBU[2021-06-23T10:46:47+01:00] Executed &irc.Message{Prefix:(*irc.Prefix)(nil), Command:"PRIVMSG", Params:[]string{"#off-topic"}, Trailing:"But i can't reply", EmptyTrailing:false} &model.AppError{Id:"api.context.session_expired.app_error", Message:"Invalid or expired session, please login again.", DetailedError:"", RequestId:"<id>", StatusCode:401, Where:"", IsOAuth:false, params:map[string]interface {}(nil)}  module=matterircd
ERRO[2021-06-23T10:46:47+01:00] handler error for <id>: : Invalid or expired session, please login again.,   module=matterircd
[2021-06-23T10:46:47+01:00] DEBUG matterclient: WsReceiver response: &model.WebSocketResponse{Status:"OK", SeqReply:6, Data:map[string]interface {}{"node_id":"", "server_time":1.624441607866e+12, "text":"pong", "version":"5.34.0"}, Error:(*model.AppError)(nil)}
[2021-06-23T10:46:47+01:00] DEBUG matterclient: getting response: &model.WebSocketResponse{Status:"OK", SeqReply:6, Data:map[string]interface {}{"node_id":"", "server_time":1.624441607866e+12, "text":"pong", "version":"5.34.0"}, Error:(*model.AppError)(nil)}
[2021-06-23T10:46:48+01:00] DEBUG matterclient: WsReceiver event: &model.WebSocketEvent{Event:"channel_viewed", Data:map[string]interface {}{"channel_id":"frf8rkpxutn83yjd7jwahh6ifh"}, Broadcast:(*model.WebsocketBroadcast)(0xc000264300), Sequence:6, precomputedJSON:(*model.precomputedWebSocketEventJSON)(nil)}
DEBU[2021-06-23T10:46:48+01:00] MMUser WsReceiver: &model.WebSocketEvent{Event:"channel_viewed", Data:map[string]interface {}{"channel_id":"<channeid>"}, Broadcast:(*model.WebsocketBroadcast)(0xc000264300), Sequence:6, precomputedJSON:(*model.precomputedWebSocketEventJSON)(nil)} 

This is with version 0.22.0. It persists in 0.24.2 (5.34.0.5.34.2.9a2e430a5e80e46c9702deb3baeef177.true).

yourealwaysbe commented 3 years ago

Ok, i fixed this for me. I was logging in with

/msg mattermost server team user MMAUTHTOKEN=<my mmauthtoken from cookies>

changing that to

/msg mattermost server team user token=<my mmauthtoken from cookies>

seems to have solved it.

42wim commented 3 years ago

I'm going to close this now then :)

yourealwaysbe commented 3 years ago

The documentation on this could do with a quick update though (it says to use MMAUTHTOKEN): https://github.com/42wim/matterircd#mattermost-login-with-ssogitlab

42wim commented 3 years ago

@yourealwaysbe well it should be MMAUTHTOKEN, when using the token option you're using a "personal access token". I can add it as an extra "if it doesn't work try token="