-
Notifications
You must be signed in to change notification settings - Fork 0
/
mattermost-auth
executable file
·59 lines (44 loc) · 1.86 KB
/
mattermost-auth
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python3
import sys
import click
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
def get_auth_cookie(domain, login, password):
chrome_options = webdriver.ChromeOptions()
chrome_options.headless = True
driver = webdriver.Chrome(options=chrome_options)
driver.get("https://{}/login".format(domain))
WebDriverWait(driver, 10).until(EC.title_contains("GitLab"))
gitlabElement = driver.find_element_by_partial_link_text("GitLab")
# inputElement = driver.find_element_by_class_name("gitlab")
gitlabElement.click()
WebDriverWait(driver, 10).until(EC.title_contains("GitLab"))
emailElement = driver.find_element_by_id('user_login')
emailElement.send_keys(login)
passwordElement = driver.find_element_by_id('user_password')
passwordElement.send_keys(password)
passwordElement.submit()
WebDriverWait(driver, 10).until(EC.title_contains("Mattermost"))
auth_cookie = None
for cookie in driver.get_cookies():
if cookie['name'] == 'MMAUTHTOKEN':
auth_cookie = cookie
driver.quit()
return auth_cookie
@click.command()
@click.option('-d', '--domain', required=True, help='Domain to use')
@click.option('-t', '--team', required=True, help='Mattermost team name')
@click.option('-u', '--user', required=True, help='Username')
@click.option('-p', '--password', required=True, help='Password')
def main(domain, team, user, password):
# TODO: caching?
try:
cookie = get_auth_cookie(domain, user, password)
token = cookie['value']
print('login {} {} {} token={}'.format(domain, team, user, token))
except TimeoutException:
print('timeout', file=sys.stderr)
if __name__ == "__main__":
main()