Skip to content

Instantly share code, notes, and snippets.

@itsmikeq
Last active December 18, 2015 08:19
Show Gist options
  • Save itsmikeq/5752955 to your computer and use it in GitHub Desktop.
Save itsmikeq/5752955 to your computer and use it in GitHub Desktop.
Accessing an Atom feed behind Site Minder
#!perl
#
# Example script to connect to an ATOM feed behind SiteMinder
# Usage: feed_parser.pl <username> <password> <url>
# URL Can also be copied and pasted from the Atom feed link at the bottom
# of any project
#
#
use strict;
use LWP;
use HTTP::Cookies;
use LWP::Authen::Basic;
use Data::Dumper;
my $username = $ARGV[0];
my $password = $ARGV[1];
my $feed_uri = $ARGV[2];
$ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'} = 0;
# Create a cookie jar to store cookies
my $cookie_jar = HTTP::Cookies->new(
file => "$ENV{'HOME'}/lwp_cookies.dat",
autosave => 1,
);
#### Set up UA #####
my %options = {};
my $ua = LWP::UserAgent->new( %options );
#$ua->agent('Mozilla/5.0');
$ua->cookie_jar($cookie_jar);
push @{ $ua->requests_redirectable }, 'POST';
#### END Set up UA #####
print "Connecting to $feed_uri\n";
my $request = HTTP::Request->new(GET => $feed_uri);
my $get_response = $ua->request($request);
# Get the realm
my $realm = $get_response->{'_headers'}->{'www-authenticate'};
# Parse out the real realm
(undef, $realm) = split(/=/,$realm);
print "Realm: $realm\n";
# Add the login info to the UA
$ua->credentials( $get_response->{'_headers'}->{'client-peer'}, $realm, $username, $password );
# Here we are going to get bounced out to the redirected URL
print $get_response->headers()->as_string;
my $bounce_url = $get_response->request->uri;
print "Redirected URL: ", $bounce_url, "\n";
my $auth_get_request = HTTP::Request->new(GET => $bounce_url);
# Add in some basic auth
$auth_get_request->authorization_basic($username, $password);
# Create the new request
my $auth_get_response = $ua->request($auth_get_request);
# Now we have our feed to pipe through an ATOM feed parser
my $atom_feed = $auth_get_response->content;
print "Atom Feed: ", $atom_feed, "\n";
exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment