Skip to content

Instantly share code, notes, and snippets.

@mgregoro
Last active March 30, 2017 17:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgregoro/2b824338620e7b1bb2c948d0b92e2cb9 to your computer and use it in GitHub Desktop.
Save mgregoro/2b824338620e7b1bb2c948d0b92e2cb9 to your computer and use it in GitHub Desktop.
destination_url= based daisy chaining for wsu SSO
#!/usr/bin/env perl
use v5.10;
use Mojo::URL;
unless ($ARGV[0]) {
say "Usage: dester.pl <url1> <url2> <url3> <urlN>";
print <<"EOF";
You ever be like "man, I need to daisy chain a bunch of Mikey's crazy destination_url= based sso crap
and I just dont know how many times to escape it or what the hell is going on", well this is a solution
to that problem. Simply run dester.pl with the URLs in the order you wish them to be hit, you can even
include other GET parameters in them, and dester.pl will cleverly insert its destination_url right where
you need it without any fuss.
dester.pl: the choice of America.
EOF
}
say get_chain_url(@ARGV);
sub get_chain_url {
my (@urls) = reverse(@_);
my $count = $#urls;
my $i = 0;
my $last;
my $chain_url;
foreach my $u (@urls) {
if ($i == 0) {
$url = Mojo::URL->new($u)->to_string;
$last = $url;
} elsif ($i < $count) {
$url = Mojo::URL->new($u);
$url->query([destination_url => $last]);
$last = $url->to_string;
} else {
$url = Mojo::URL->new($u);
$chain_url = $url->query([destination_url => $last])->to_string;
}
$i++;
}
return $chain_url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment