Skip to content

Instantly share code, notes, and snippets.

@codingtony
Last active August 29, 2015 14:06
Show Gist options
  • Save codingtony/b2ceb2aa0aa5cd83eab8 to your computer and use it in GitHub Desktop.
Save codingtony/b2ceb2aa0aa5cd83eab8 to your computer and use it in GitHub Desktop.
Script to check success of login on Butor FrameworkSSO. This script uses curl. The script will generate an ERROR if HTTP CODE != 200 OR if message type=ERROR is present in the payload returned. Exit code of this script will be 0 only if login succeed.
#!/bin/bash
USER=$1
PASSWORD=$2
LOGIN_AJAX_SERVICE=$3
if [ -z "$1" ]; then
echo "ERROR: USER REQUIRED (first parameter)";
exit 1;
fi
if [ -z "$2" ]; then
echo "ERROR: PASSWORD REQUIRED (second parameter)";
exit 1;
fi
if [ -z "$3" ]; then
echo "ERROR: LOGIN_AJAX_SERVICE REQUIRED (third parameter), e.g. https://site.com/sso/login.ajax";
exit 1
fi
ARGS="args=[{\"id\":\"$USER\",\"pwd\":\"$PASSWORD\"}]"
curl ${LOGIN_AJAX_SERVICE} --data 'streaming=false&service=signInS1&lang=en&'${ARGS} --write-out '\t%{http_code}\n' -s 2>&1 | perl -nale '
my $ok=0;
if ($_ =~ m/\t200/) {
unless ($_ =~ m/"type":"ERROR"/ ) {
$ok=1;
}
}
if ($ok) {
print "OK";
} else {
print "ERROR LOGIN : $_";
die;
}';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment