LWP::UserAgent::Keychain - UserAgent that looks up passwords on Mac OS X keychain


LWP-UserAgent-Keychain documentation Contained in the LWP-UserAgent-Keychain distribution.

Index


Code Index:

NAME

Top

LWP::UserAgent::Keychain - UserAgent that looks up passwords on Mac OS X keychain

SYNOPSIS

Top

  use LWP::UserAgent::Keychain;

  my $ua = LWP::UserAgent::Keychain->new;
  $ua->get("http://proteceted.example.com/");

DESCRIPTION

Top

LWP::UserAgent::Keychain is a LWP UserAgent object and it tries to lookup username and password on Mac OS X keychain when it encounters the page secured under HTTP basic or digest authentication.

By default, the tries to find the Internet Key in the keychain named Login.

AUTHOR

Top

Tatsuhiko Miyagawa <miyagawa@cpan.org>

LICENSE

Top

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

Top

Mac::Glue, LWP


LWP-UserAgent-Keychain documentation Contained in the LWP-UserAgent-Keychain distribution.

package LWP::UserAgent::Keychain;

use strict;
use 5.8.1;
our $VERSION = '0.01';

use Mac::Glue ':all';
use base qw( LWP::UserAgent );

my $keychain = Mac::Glue->new("Keychain Scripting");

sub get_basic_credentials {
    my($self, $realm, $uri, $isproxy) = @_;

    for my $key ($keychain->obj(keys => keychain => "Login.keychain")->get) {
        if ($key->prop('class')->get eq 'cint' and
            $key->prop('server')->get eq $uri->host and
            $key->prop('protocol')->get eq $uri->scheme) {

            my $username = $key->prop('account')->get;
            my $password = $key->prop('password')->get;
            return ($username, $password);
        }
    }

    return (undef, undef);
}

1;
__END__