I figured that I wouldn't need to set up cookies because one of the
features listed under the WWW::Mechanize module is "Automatic
cookies."  It also says, "If you want none of the overhead of a cookie
jar, or don't want your bot accepting cookies, you have to explicitly
disallow it."  If this assumption is incorrect, please let me know.
Here is what I have so far:

#! /usr/bin/perl

use strict;
use warnings;
use feature 'say';
use WWW::Mechanize;

# Create a new Mech object
my $mech = WWW::Mechanize->new("autocheck" => 1);
$mech->agent_alias('Linux Mozilla');
$mech->timeout(300);

my ($un, $pw) = { "USERNAME", "PASSWORD" };

# Get login page
$mech->get("https://ry.byu.edu";);

# Fill in login info and submit
$mech->form_with_fields("username", "password");
$mech->set_fields("username" => $un,
"password" => $pw);
$mech->submit() or die "could not log in: " .
$mech->response->status_line . "\n";

# Grab example site that requires CAS login
say "Current page:";
$mech->get("https://home.byu.edu/webapp/mymap/register.htm";);
say $mech->content(format => 'text');

# The output of $mech->content is the CAS login page

2010/10/29 Michael Torrie <[email protected]>:
> On 10/29/2010 12:46 PM, Dallin Terry wrote:
>> Has anyone successfully logged into CAS using the WWW::Mechanize
>> module in PERL?  I found an old UUG post (link below) that attempts to
>> do about the same thing.  I modified it to go to the actual CAS login
>> page instead of grabbing the form from the homepage (which I'm not
>> sure exists anymore).  Whenever I attempt to log in, then go to a
>> different page that requires CAS authentication, it redirects me back
>> to the CAS logon page; this leads me to believe it's not logging in
>> correctly, but it doesn't seem to return the authentication failure
>> page.
>
> Did you set up cookies?  A successful CAS login will return a
> ticket-granting cookie that you have to pass along to any site that is
> CASified.
> --------------------
> BYU Unix Users Group
> http://uug.byu.edu/
>
> The opinions expressed in this message are the responsibility of their
> author.  They are not endorsed by BYU, the BYU CS Department or BYU-UUG.
> ___________________________________________________________________
> List Info (unsubscribe here): http://uug.byu.edu/mailman/listinfo/uug-list
>



--
Dallin Terry
--------------------
BYU Unix Users Group 
http://uug.byu.edu/ 

The opinions expressed in this message are the responsibility of their
author.  They are not endorsed by BYU, the BYU CS Department or BYU-UUG. 
___________________________________________________________________
List Info (unsubscribe here): http://uug.byu.edu/mailman/listinfo/uug-list

Reply via email to