Created
November 28, 2018 12:46
-
-
Save muxueqz/d61007a357266b8c7476a3ae09b2723b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
workdir=/dev/shm/gitlab_auth_by_sh | |
mkdir -pv ${workdir} | |
cookies_file=`mktemp -p ${workdir}` | |
rm -rfv $cookies_file | |
gitlab_host="https://git_host" | |
gitlab_user=$username | |
gitlab_password=$password | |
# curl for the login page to get a session cookie and the sources with the auth tokens | |
body_header=$(curl -c $cookies_file -i "${gitlab_host}/users/sign_in" -s) | |
# grep the auth token for the user login for | |
# not sure whether another token on the page will work, too - there are 3 of them | |
csrf_token=$(echo $body_header | grep -oP '(name="authenticity_token" value=")[^"]*' | cut -d'"' -f4) | |
# send login credentials with curl, using cookies and token from previous request | |
curl -b $cookies_file -c $cookies_file -i "${gitlab_host}/users/sign_in" \ | |
--data "user[login]=${gitlab_user}&user[password]=${gitlab_password}" \ | |
--data-urlencode "authenticity_token=${csrf_token}" -v | |
login_status=$(curl -b $cookies_file "${gitlab_host}/api/v4/user" | grep active -c) | |
rm -rfv ${cookies_file} | |
if [[ $login_status == 1 ]];then | |
echo 0 | |
else | |
echo 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment