Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for StackExchange #31

Open
cereda opened this issue May 6, 2016 · 17 comments
Open

Support for StackExchange #31

cereda opened this issue May 6, 2016 · 17 comments

Comments

@cereda
Copy link

cereda commented May 6, 2016

Hi there, congrats for the cool project! 😉

Is there any plan for supporting StackExchange-based chatrooms? I did a couple of tests and it looks doable: although I could not make the bot successfully login, it intercepts messages and parses them accordingly, so it seems we are almost there. 😉

Just a quick info: maybe the fkey regex should be redone as the format looks quite different in SE sites (as it incorporates arbitrary length and hyphens). An alternative solution is to rely on jsoup for getting data from HTML sources.

Keep up the good work! 🍰

All the best,

Paulo

@mangstadt
Copy link
Member

Hi Paulo,

If the format of the fkey is the only difference, it sounds like supporting StackExchange would be relatively straightforward. Can you tell me how the fkey looks for a StackExchange chat room?

Thank you,
Mike

@cereda
Copy link
Author

cereda commented May 9, 2016

Hi Mike!

Sadly, I could not spend much time in the code, as I have a thesis to write (ouch). 😉 To the extent of my checking, the StackExchange fkey seems to keep the usual 32 hexadecimal digits with the addition of four hyphens acting as separators. I suspect the regex could be expressed along the lines of value=\"([0-9a-f\-]{36})\" (untested).

Still, the login part looks a bit tricky, as it is done via StackExchange OpenID (and the site sometimes redirects connections). I was looking at ChatExchange for some hints, and it seems the OpenID part requires some tweaking indeed. But, apart from this nuisance, the port looks potentially doable (I am trying to be cautious on saying strong statements 😉 ).

I offer my help to tackle the login part, although my time is quite restricted nowadays. And please, feel free to ignore this request if, at the end of the day, tweaking the code would cause a lot of headaches. 😉

All the best!

Paulo

@mangstadt
Copy link
Member

Thank you for the information, Paulo. It sounds like it's not as simple as originally thought. :( However, this would surely be a nice feature to add. Maybe I will work on it later. Good luck with your thesis!

@LunarWatcher
Copy link
Contributor

Repoking this issue: I have added support for Stack Exchange in my bot (based on OakBot). Simply changing the domain is enough. There are however some pitfalls to be aware of:

  • User IDs
  • Room IDs

Those should be fairly self-explanatory. Once you change the site, user ID's change. Room ID's too. Passing the domain allows you to get the appropriate property from bot.properties (for an instance so_admins and mse_admins. Check the domain, set admins to the right one). Passing domain to Rooms (class) you can append that to the name (for an instance stackoverflow.com-rooms, meta.stackoverflow.com-rooms) which saves the appropriate room IDs to the appropriate database entry.

I'm still working on implementing this, primarily connected with meta stackexchange but it appears to be universal. any *.stackexchange.com has chat at chat.stackexchange.com. Custom domains (stackoverflow.com, superuser.com, etc) have at their own domains. Checked the fkey regex, and looked for the fkey in Shadows Den (on meta stackexchange chat) and it matched. 32 hex.

As for login, changing the domain in StackOverflowWSEvents (added a second constructor, domain defaults to stackoverflow if not defined) and nothing else allows login.

It is primarily admin ID's, banned ID's and bot ID that causes issues. Still working on implementing fixes in my bot

@mangstadt
Copy link
Member

Cool, thanks for the additional info. :)

@cereda
Copy link
Author

cereda commented Oct 2, 2018

Hi friends!

Sorry for the huge hiatus (note to self: PhD takes more time than expected). Any updates on this? I tried the code a couple of minutes ago and I failed to make it work on a StackExchange room. Perhaps @LunarWatcher could give me some hints. 😉

All the best!

@mangstadt
Copy link
Member

No, sorry. :( Haven't worked much on Stack Exchange compatibility. Also: ducks!

@cereda
Copy link
Author

cereda commented Oct 5, 2018

Hi Mike!

No worries, pal. 😉

Duck

Quack! 😉

@LunarWatcher
Copy link
Contributor

Just as a heads-up, SE openID is deprecated, which can result in problems with login to SE later. SO login, as originally done in the bot, is fortunately not affected. But login into SE chat still uses OpenID. Meta.SE login is virtually the same as into SO, but SE is still complicated because it uses different endpoints.

First you POST to https://stackexchange.com/users/login#log-in, and get a URL from the body. You use that URL to get the fkey, which you then POST along with username and password to https://openid.stackexchange.com/affiliate/form/login/submit, in addition to affId set to 11. Finally, using that response, you create a final response using a URL in some JS code called var target. GET that, no arguments used here, and then check the response for the status on the login.

@cereda
Copy link
Author

cereda commented Oct 5, 2018

Hi @LunarWatcher! Thank you very much for the heads up, I will try to delve into the code. 😉

Quack! 🦆

@mangstadt
Copy link
Member

@LunarWatcher Do you have any code you could post for the SE login? Or know where I can find some? I spent about an hour trying to get something to work, with no luck.

The hard part is that the SE login page uses JavaScript to submit the credentials. The login URL that you posted wouldn't quite work with the bot at face value because the anchor ("#log-in") causes some JavaScript to run in the browser.

@mangstadt
Copy link
Member

mangstadt commented Oct 8, 2018

Never mind. I think I figured it out! I was trying to use Firefox's F12 developer menu, but it was clearing the list of network requests on every click, so I couldn't see the URLs the browser was sending requests to. Edge actually worked better. 😵

  1. Send GET request to https://stackexchange.com/users/signin.
  2. A plain-text URL will be returned. Send a GET request to this url.
  3. An HTML page containing a login form will be returned. Extract the form URL, affId, and fkey from this form.
  4. Send a POST request to the form's URL. Include the following parameters: email, password, affId, fkey.
  5. An HTML page will be returned. If the login credentials are correct, the page will contain a JavaScript "target" variable, which is set to a URL. Extract this URL.
  6. Send a GET request to the above URL.
  7. You are now logged in,

@mangstadt
Copy link
Member

Ok, I think I got it working! Thanks for your tips @LunarWatcher!

Let me know how it works if you try it out! 🎉

@cereda
Copy link
Author

cereda commented Oct 12, 2018

Brilliant, friends! It's working like a charm! Time to revive our beloved Psmith! All the best!

@cereda cereda closed this as completed Oct 12, 2018
@cereda
Copy link
Author

cereda commented Apr 21, 2019

Friends, sorry to bump this issue, but I do believe recent changes in SE broke the support. I will try to take a closer look during this week and report back...

Happy Easter! 😉

@mangstadt
Copy link
Member

Ugh, just great. 😕 Thanks for letting us know! 😀

@mangstadt mangstadt reopened this Apr 23, 2019
@cereda
Copy link
Author

cereda commented Apr 23, 2019

Deeply sorry @mangstadt... 😢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants