Skip to content

Instantly share code, notes, and snippets.

@atarkowska
Created January 18, 2016 12:12
Show Gist options
  • Save atarkowska/9d5ed3033c3f9126c397 to your computer and use it in GitHub Desktop.
Save atarkowska/9d5ed3033c3f9126c397 to your computer and use it in GitHub Desktop.
Log in to OMERO.web
#!/bin/bash
#
set -u
set -e
set -x
COOKIES=cookies.txt
LOGIN_URL=https://omero.host/prefix/webclient/login/
LOGOUT_URL=https://omero.host/prefix/webclient/logout/
USERNAME='username'
PASSWD='omero'
SERVER='1'
CURL_CMD="curl -i -k -s -c $COOKIES -b $COOKIES "
echo -n "Django Auth: get csrftoken ..."
$CURL_CMD $LOGIN_URL > /dev/null
csrf_token=$(grep csrftoken $COOKIES | sed 's/^.*csrftoken\s*//' | sed -e 's/^[[:space:]]*//' )
echo -n $csrf_token
DJANGO_TOKEN="csrfmiddlewaretoken=$csrf_token"
echo -n $DJANGO_TOKEN
echo -n "Perform login ..."
$CURL_CMD \
-e $LOGIN_URL \
-d "$DJANGO_TOKEN&username=$USERNAME&password=$PASSWD&server=$SERVER" \
-X POST $LOGIN_URL
echo -n "You are logged in!"
echo -n "Load Experimenter:"
$CURL_CMD \
-X GET https://omero.host/prefix/webclient/api/experimenters/0/
echo -n "Perform logout ..."
$CURL_CMD \
-e $LOGIN_URL \
-d "$DJANGO_TOKEN" \
-X POST $LOGOUT_URL
echo "You are logged out!"
rm $COOKIES
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment