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