OpenID2 in progress (#595)

This commit is contained in:
Xavier Guimard 2017-01-05 16:44:16 +00:00
parent b3f1415626
commit e4bf8ac619
3 changed files with 73 additions and 19 deletions

View File

@ -3,6 +3,7 @@ package Lemonldap::NG::Portal::Issuer::OpenID;
use strict;
use JSON;
use Mouse;
use Lemonldap::NG::Common::Regexp;
use Lemonldap::NG::Portal::Main::Constants qw(
PE_BADPARTNER
PE_CONFIRM
@ -47,14 +48,7 @@ has spList => (
}
);
has openidPortal => (
is => 'rw',
default => sub {
return $_[0]->conf->{portal} . '/' . $_[0]->path;
#$openidPortal =~ s#(?<!:)//#/#g;
}
);
has openidPortal => ( is => 'rw' );
# INITIALIZATION
@ -65,6 +59,10 @@ sub init {
$self->error("Unable to load Net::OpenID::Server: $@");
return 0;
}
return 0 unless ( $self->SUPER::init() );
$self->openidPortal( $self->conf->{portal} . '/' . $self->path );
#$openidPortal =~ s#(?<!:)//#/#g;
return 1;
}
@ -119,7 +117,8 @@ sub openIDServer {
my ( $self, $req ) = @_;
return $req->datas->{_openidserver} if ( $req->datas->{_openidserver} );
$req->datas->{_openidserver} = Lemonldap::NG::Portal::Lib::OpenID::Server->new(
$req->datas->{_openidserver} =
Lemonldap::NG::Portal::Lib::OpenID::Server->new(
server_secret => sub { return $self->secret },
args => $req,
endpoint_url => $self->openidPortal,
@ -179,10 +178,12 @@ sub openIDServer {
sreg => sub {
return ( 1, {} ) unless (@_);
require Lemonldap::NG::Portal::Lib::OpenID::SREG;
return $self->Lemonldap::NG::Portal::Lib::OpenID::SREG::sregHook($req, @_);
return
$self->Lemonldap::NG::Portal::Lib::OpenID::SREG::sregHook(
$req, @_ );
},
},
);
);
return $req->datas->{_openidserver};
}

View File

@ -268,8 +268,10 @@ sub loadPlugin {
qw(beforeAuth betweenAuthAndDatas afterDatas forAuthUser beforeLogout))
{
if ( $obj->can($sub) ) {
$self->lmLog( " Found $sub entry point:", 'debug' );
if ( my $callback = $obj->$sub ) {
push @{ $self->{$sub} }, sub { $obj->$callback( $_[0] ) };
$self->lmLog( " -> $callback", 'debug' );
}
}
}
@ -300,7 +302,7 @@ sub loadModule {
}
sub fail {
$_[0]->lmLog($_[0]->error,'error');
$_[0]->lmLog( $_[0]->error, 'error' );
return 0;
}

View File

@ -7,7 +7,7 @@ BEGIN {
require 't/test-lib.pm';
}
my $maintests = 3;
my $maintests = 4;
my $debug = 'debug';
my ( $issuer, $sp, $res );
my %handlerOR = ( issuer => [], sp => [] );
@ -32,6 +32,18 @@ SKIP: {
),
'Unauth SP request'
);
expectForm( $res, '#', undef );
ok( $res->[2]->[0] =~ /name="openid_identifier"/, ' Found OpenID input' );
my $query =
'openid_identifier=http%3A%2F%2Fauth.idp.com%2Fopenidserver%2Fdwho';
#ok(
# $res = $sp->_post(
# '/', IO::String->new($query), length => length($query),
# ),
# 'Post OpenID identity'
#);
#print STDERR Dumper($res);
}
@ -46,16 +58,54 @@ sub switch {
};
}
no warnings 'redefine';
sub LWP::UserAgent::request {
my ( $self, $req ) = @_;
ok( $req->uri =~ m#http://auth.idp.com(.*)#, ' Request from SP to IdP' );
my $url = $1;
my ($res);
count(1);
print STDERR Dumper($req);
if ( $req->method =~ /^post$/i ) {
my $s = $req->content;
ok(
$res = $issuer->_post(
$url, IO::String->new($s),
length => length($s),
type => $req->header('Content-Type'),
),
' Execute request'
);
}
else {
ok( $res = $issuer->_get( $url, ), ' Execute request' );
}
expectOK($res);
ok( getHeader( $res, 'Content-Type' ) =~ m#^application/json#,
' Content is JSON' )
or explain( $res->[1], 'Content-Type => application/json' );
my $httpResp = HTTP::Response->new( $res->[0], 'OK' );
while ( my $name = shift @{ $res->[1] } ) {
$httpResp->header( $name, shift( @{ $res->[1] } ) );
}
$httpResp->content( join( '', @{ $res->[2] } ) );
count(2);
return $httpResp;
}
sub issuer {
return LLNG::Manager::Test->new(
{
ini => {
logLevel => $debug,
templatesDir => 'site/htdocs/static',
domain => 'idp.com',
portal => 'http://auth.idp.com',
authentication => 'Demo',
userDB => 'Demo',
logLevel => $debug,
templatesDir => 'site/htdocs/static',
domain => 'idp.com',
portal => 'http://auth.idp.com',
authentication => 'Demo',
userDB => 'Demo',
issuerDBOpenIDActivation => 1,
}
}
);
@ -70,6 +120,7 @@ sub sp {
portal => 'http://auth.sp.com',
authentication => 'OpenID',
userDB => 'OpenID',
openIdSecret => 'qwerty',
},
}
);