Skip to content

Instantly share code, notes, and snippets.

@Centzilius
Created October 19, 2021 01:03
Show Gist options
  • Save Centzilius/54021ee10d898cfb31587677f1b41956 to your computer and use it in GitHub Desktop.
Save Centzilius/54021ee10d898cfb31587677f1b41956 to your computer and use it in GitHub Desktop.
Mattermost Auth Token extractor for MM + GitLab + LDAP
from requests import session
import re
username = ""
password = ""
gitlab_url = "https://gitlab.example.com"
mattermost_url = "https://mattermost.example.com"
sess = session()
csrf = re.search(
r'<meta name="csrf-token" content="([^"]+)" \/>',
sess.get(f"{gitlab_url}/users/sign_in").text
).groups()[0]
gitlab_login = sess.post(
f"{gitlab_url}/users/auth/ldapmain/callback",
data={
"authenticity_token": csrf,
"username": username,
"password": password
}
)
sess.get(re.search(
r'window.location= "([^\"]+)',
sess.get(f"{mattermost_url}/oauth/gitlab/login").text
).groups()[0])
print(sess.cookies["MMAUTHTOKEN"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment