Centralize LWP::UserAgent in one file.
This commit is contained in:
parent
5354fc3361
commit
bb4e4668e5
|
@ -7,10 +7,11 @@ package Lemonldap::NG::Portal::AuthBrowserID;
|
|||
|
||||
use strict;
|
||||
use Lemonldap::NG::Portal::Simple;
|
||||
use LWP::UserAgent;
|
||||
use Lemonldap::NG::Portal::_Browser;
|
||||
use HTTP::Request;
|
||||
use JSON;
|
||||
|
||||
our @ISA = (qw(Lemonldap::NG::Portal::_Browser));
|
||||
our $VERSION = '1.3.0';
|
||||
|
||||
## @apmethod int authInit()
|
||||
|
@ -69,9 +70,6 @@ sub extractFormInfo {
|
|||
'debug' );
|
||||
|
||||
# Resolve assertion
|
||||
my $ua = new LWP::UserAgent;
|
||||
push @{ $ua->requests_redirectable }, 'POST';
|
||||
|
||||
my $postdata =
|
||||
"assertion="
|
||||
. $self->{browserIdAssertion}
|
||||
|
@ -86,7 +84,7 @@ sub extractFormInfo {
|
|||
$request->content_type('application/x-www-form-urlencoded');
|
||||
$request->content($postdata);
|
||||
|
||||
my $answer = $ua->request($request);
|
||||
my $answer = $self->ua()->request($request);
|
||||
|
||||
$self->lmLog( "Verification response: " . $answer->as_string, 'debug' );
|
||||
|
||||
|
|
|
@ -11,9 +11,10 @@ package Lemonldap::NG::Portal::AuthFacebook;
|
|||
use strict;
|
||||
use Lemonldap::NG::Portal::Simple;
|
||||
use Lemonldap::NG::Common::Regexp;
|
||||
use LWP::UserAgent;
|
||||
use Lemonldap::NG::Portal::_Browser;
|
||||
use URI::Escape;
|
||||
|
||||
our @ISA = (qw(Lemonldap::NG::Portal::_Browser));
|
||||
our $VERSION = '1.3.0';
|
||||
our $initDone;
|
||||
|
||||
|
@ -24,13 +25,6 @@ BEGIN {
|
|||
};
|
||||
}
|
||||
|
||||
## @method LWP::UserAgent ua()
|
||||
# @return LWP::UserAgent object
|
||||
sub ua {
|
||||
my $self = shift;
|
||||
return $self->{ua} ||= LWP::UserAgent->new();
|
||||
}
|
||||
|
||||
## @method Net::Facebook::Oauth2 fb()
|
||||
# @return Net::Facebook::Oauth2 object
|
||||
sub fb {
|
||||
|
|
|
@ -8,12 +8,13 @@ package Lemonldap::NG::Portal::AuthGoogle;
|
|||
use strict;
|
||||
use Lemonldap::NG::Portal::Simple;
|
||||
use Lemonldap::NG::Common::Regexp;
|
||||
use LWP::UserAgent;
|
||||
use Lemonldap::NG::Portal::_Browser;
|
||||
use URI::Escape;
|
||||
|
||||
use constant AXSPECURL => 'http://openid.net/srv/ax/1.0';
|
||||
use constant GOOGLEENDPOINT => 'https://www.google.com/accounts/o8/id';
|
||||
|
||||
our @ISA = (qw(Lemonldap::NG::Portal::_Browser));
|
||||
our $VERSION = '1.3.0';
|
||||
our $googleEndPoint;
|
||||
|
||||
|
@ -55,13 +56,6 @@ sub googleEndPoint {
|
|||
return $googleEndPoint;
|
||||
}
|
||||
|
||||
## @method LWP::UserAgent ua()
|
||||
# @return LWP::UserAgent object
|
||||
sub ua {
|
||||
my $self = shift;
|
||||
return $self->{ua} ||= LWP::UserAgent->new();
|
||||
}
|
||||
|
||||
## @method boolean checkGoogleSession()
|
||||
# Search for claimed_id in persistent sessions DB.
|
||||
# @return true if sessions was recovered
|
||||
|
|
|
@ -9,10 +9,11 @@ package Lemonldap::NG::Portal::AuthOpenID;
|
|||
use strict;
|
||||
use Lemonldap::NG::Portal::Simple;
|
||||
use Lemonldap::NG::Common::Regexp;
|
||||
use LWP::UserAgent;
|
||||
use Lemonldap::NG::Portal::_Browser;
|
||||
use Cache::FileCache;
|
||||
|
||||
our $VERSION = '1.2.0';
|
||||
our @ISA = (qw(Lemonldap::NG::Portal::_Browser));
|
||||
our $VERSION = '1.3.0';
|
||||
our $initDone;
|
||||
|
||||
BEGIN {
|
||||
|
@ -48,11 +49,8 @@ sub authInit {
|
|||
sub extractFormInfo {
|
||||
my $self = shift;
|
||||
|
||||
my $ua = LWP::UserAgent->new();
|
||||
|
||||
# TODO : LWP options to use a proxy for example
|
||||
$self->{csr} = Net::OpenID::Consumer->new(
|
||||
ua => $ua,
|
||||
ua => $self->ua(),
|
||||
cache => $self->{refLocalStorage} || Cache::FileCache->new,
|
||||
args => $self,
|
||||
consumer_secret => $self->{openIdSecret},
|
||||
|
|
29
lemonldap-ng-portal/lib/Lemonldap/NG/Portal/_Browser.pm
Normal file
29
lemonldap-ng-portal/lib/Lemonldap/NG/Portal/_Browser.pm
Normal file
|
@ -0,0 +1,29 @@
|
|||
##@file
|
||||
# Add LWP::UserAgent object
|
||||
|
||||
##@class
|
||||
# Add LWP::UserAgent object
|
||||
package Lemonldap::NG::Portal::_Browser;
|
||||
|
||||
use strict;
|
||||
|
||||
our $VERSION = '1.3.0';
|
||||
our $_ua;
|
||||
|
||||
## @method LWP::UserAgent ua()
|
||||
# @return LWP::UserAgent object
|
||||
sub ua {
|
||||
my $self = shift;
|
||||
|
||||
return $_ua if ($_ua);
|
||||
eval { require LWP::UserAgent; };
|
||||
$self->abort( 'LWP::UserAgent isn\'t installed', $@ ) if ($@);
|
||||
|
||||
# TODO : LWP options to use a proxy for example
|
||||
$_ua = LWP::UserAgent->new() or $self->abort($@);
|
||||
push @{ $_ua->requests_redirectable }, 'POST';
|
||||
return $_ua;
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
@ -6,9 +6,10 @@
|
|||
package Lemonldap::NG::Portal::_CAS;
|
||||
|
||||
use strict;
|
||||
use LWP::UserAgent;
|
||||
use Lemonldap::NG::Portal::_Browser;
|
||||
|
||||
our $VERSION = '1.0.0';
|
||||
our @ISA = (qw(Lemonldap::NG::Portal::_Browser));
|
||||
our $VERSION = '1.3.0';
|
||||
|
||||
## @method hashref getCasSession(string id)
|
||||
# Try to recover the CAS session corresponding to id and return session datas
|
||||
|
@ -238,10 +239,7 @@ sub deleteCasSession {
|
|||
sub callPgtUrl {
|
||||
my ( $self, $pgtUrl, $pgtIou, $pgtId ) = splice @_;
|
||||
|
||||
# LWP User Agent
|
||||
my $ua = new LWP::UserAgent;
|
||||
push @{ $ua->requests_redirectable }, 'POST';
|
||||
$ua->env_proxy();
|
||||
$self->ua()->env_proxy();
|
||||
|
||||
# Build URL
|
||||
my $url = $pgtUrl;
|
||||
|
@ -251,7 +249,7 @@ sub callPgtUrl {
|
|||
$self->lmLog( "Call URL $url", 'debug' );
|
||||
|
||||
# GET URL
|
||||
my $response = $ua->get($url);
|
||||
my $response = $self->ua()->get($url);
|
||||
|
||||
# Return result
|
||||
return $response->is_success();
|
||||
|
|
|
@ -7,10 +7,10 @@ package Lemonldap::NG::Portal::_SAML;
|
|||
|
||||
use strict;
|
||||
use Lemonldap::NG::Common::Conf::SAML::Metadata;
|
||||
use Lemonldap::NG::Portal::_Browser;
|
||||
use XML::Simple;
|
||||
use MIME::Base64;
|
||||
use String::Random;
|
||||
use LWP::UserAgent; # SOAP call
|
||||
use HTTP::Request; # SOAP call
|
||||
use POSIX qw(strftime); # Convert SAML2 date into timestamp
|
||||
use Time::Local; # Convert SAML2 date into timestamp
|
||||
|
@ -20,6 +20,7 @@ use URI; # Get metadata URL path
|
|||
# Special comments for doxygen
|
||||
#inherits Lemonldap::NG::Common::Conf::SAML::Metadata protected service_metadata
|
||||
|
||||
our @ISA = (qw(Lemonldap::NG::Portal::_Browser));
|
||||
our $VERSION = '1.3.0';
|
||||
our $samlCache;
|
||||
our $initGlibDone;
|
||||
|
@ -1662,10 +1663,6 @@ sub resolveArtifact {
|
|||
my ( $self, $profile, $artifact, $method ) = splice @_;
|
||||
my $message;
|
||||
|
||||
# LWP User Agent
|
||||
my $ua = new LWP::UserAgent;
|
||||
push @{ $ua->requests_redirectable }, 'POST';
|
||||
|
||||
# Login profile
|
||||
if ( $profile->isa("Lasso::Login") ) {
|
||||
|
||||
|
@ -1691,7 +1688,7 @@ sub resolveArtifact {
|
|||
'debug' );
|
||||
|
||||
# SOAP call
|
||||
my $soap_answer = $ua->request($request);
|
||||
my $soap_answer = $self->ua()->request($request);
|
||||
if ( $soap_answer->code() == "200" ) {
|
||||
$message = $soap_answer->content();
|
||||
$self->lmLog( "Get message $message", 'debug' );
|
||||
|
@ -1898,10 +1895,6 @@ sub sendSOAPMessage {
|
|||
my ( $self, $endpoint, $message ) = splice @_;
|
||||
my $response;
|
||||
|
||||
# LWP User Agent
|
||||
my $ua = new LWP::UserAgent;
|
||||
push @{ $ua->requests_redirectable }, 'POST';
|
||||
|
||||
my $request = HTTP::Request->new( 'POST' => $endpoint );
|
||||
$request->content_type('text/xml');
|
||||
$request->content($message);
|
||||
|
@ -1909,7 +1902,7 @@ sub sendSOAPMessage {
|
|||
$self->lmLog( "Send SOAP message $message to $endpoint", 'debug' );
|
||||
|
||||
# SOAP call
|
||||
my $soap_answer = $ua->request($request);
|
||||
my $soap_answer = $self->ua()->request($request);
|
||||
if ( $soap_answer->code() == "200" ) {
|
||||
$response = $soap_answer->content();
|
||||
$self->lmLog( "Get response $response", 'debug' );
|
||||
|
|
Loading…
Reference in New Issue
Block a user