OpenID2 in progress (#595)
This commit is contained in:
parent
b3f1415626
commit
e4bf8ac619
|
@ -3,6 +3,7 @@ package Lemonldap::NG::Portal::Issuer::OpenID;
|
||||||
use strict;
|
use strict;
|
||||||
use JSON;
|
use JSON;
|
||||||
use Mouse;
|
use Mouse;
|
||||||
|
use Lemonldap::NG::Common::Regexp;
|
||||||
use Lemonldap::NG::Portal::Main::Constants qw(
|
use Lemonldap::NG::Portal::Main::Constants qw(
|
||||||
PE_BADPARTNER
|
PE_BADPARTNER
|
||||||
PE_CONFIRM
|
PE_CONFIRM
|
||||||
|
@ -47,14 +48,7 @@ has spList => (
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
has openidPortal => (
|
has openidPortal => ( is => 'rw' );
|
||||||
is => 'rw',
|
|
||||||
default => sub {
|
|
||||||
return $_[0]->conf->{portal} . '/' . $_[0]->path;
|
|
||||||
|
|
||||||
#$openidPortal =~ s#(?<!:)//#/#g;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
# INITIALIZATION
|
# INITIALIZATION
|
||||||
|
|
||||||
|
@ -65,6 +59,10 @@ sub init {
|
||||||
$self->error("Unable to load Net::OpenID::Server: $@");
|
$self->error("Unable to load Net::OpenID::Server: $@");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
return 0 unless ( $self->SUPER::init() );
|
||||||
|
$self->openidPortal( $self->conf->{portal} . '/' . $self->path );
|
||||||
|
|
||||||
|
#$openidPortal =~ s#(?<!:)//#/#g;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +117,8 @@ sub openIDServer {
|
||||||
my ( $self, $req ) = @_;
|
my ( $self, $req ) = @_;
|
||||||
return $req->datas->{_openidserver} if ( $req->datas->{_openidserver} );
|
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 },
|
server_secret => sub { return $self->secret },
|
||||||
args => $req,
|
args => $req,
|
||||||
endpoint_url => $self->openidPortal,
|
endpoint_url => $self->openidPortal,
|
||||||
|
@ -179,10 +178,12 @@ sub openIDServer {
|
||||||
sreg => sub {
|
sreg => sub {
|
||||||
return ( 1, {} ) unless (@_);
|
return ( 1, {} ) unless (@_);
|
||||||
require Lemonldap::NG::Portal::Lib::OpenID::SREG;
|
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};
|
return $req->datas->{_openidserver};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -268,8 +268,10 @@ sub loadPlugin {
|
||||||
qw(beforeAuth betweenAuthAndDatas afterDatas forAuthUser beforeLogout))
|
qw(beforeAuth betweenAuthAndDatas afterDatas forAuthUser beforeLogout))
|
||||||
{
|
{
|
||||||
if ( $obj->can($sub) ) {
|
if ( $obj->can($sub) ) {
|
||||||
|
$self->lmLog( " Found $sub entry point:", 'debug' );
|
||||||
if ( my $callback = $obj->$sub ) {
|
if ( my $callback = $obj->$sub ) {
|
||||||
push @{ $self->{$sub} }, sub { $obj->$callback( $_[0] ) };
|
push @{ $self->{$sub} }, sub { $obj->$callback( $_[0] ) };
|
||||||
|
$self->lmLog( " -> $callback", 'debug' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -300,7 +302,7 @@ sub loadModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub fail {
|
sub fail {
|
||||||
$_[0]->lmLog($_[0]->error,'error');
|
$_[0]->lmLog( $_[0]->error, 'error' );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ BEGIN {
|
||||||
require 't/test-lib.pm';
|
require 't/test-lib.pm';
|
||||||
}
|
}
|
||||||
|
|
||||||
my $maintests = 3;
|
my $maintests = 4;
|
||||||
my $debug = 'debug';
|
my $debug = 'debug';
|
||||||
my ( $issuer, $sp, $res );
|
my ( $issuer, $sp, $res );
|
||||||
my %handlerOR = ( issuer => [], sp => [] );
|
my %handlerOR = ( issuer => [], sp => [] );
|
||||||
|
@ -32,6 +32,18 @@ SKIP: {
|
||||||
),
|
),
|
||||||
'Unauth SP request'
|
'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);
|
#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 {
|
sub issuer {
|
||||||
return LLNG::Manager::Test->new(
|
return LLNG::Manager::Test->new(
|
||||||
{
|
{
|
||||||
ini => {
|
ini => {
|
||||||
logLevel => $debug,
|
logLevel => $debug,
|
||||||
templatesDir => 'site/htdocs/static',
|
templatesDir => 'site/htdocs/static',
|
||||||
domain => 'idp.com',
|
domain => 'idp.com',
|
||||||
portal => 'http://auth.idp.com',
|
portal => 'http://auth.idp.com',
|
||||||
authentication => 'Demo',
|
authentication => 'Demo',
|
||||||
userDB => 'Demo',
|
userDB => 'Demo',
|
||||||
|
issuerDBOpenIDActivation => 1,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -70,6 +120,7 @@ sub sp {
|
||||||
portal => 'http://auth.sp.com',
|
portal => 'http://auth.sp.com',
|
||||||
authentication => 'OpenID',
|
authentication => 'OpenID',
|
||||||
userDB => 'OpenID',
|
userDB => 'OpenID',
|
||||||
|
openIdSecret => 'qwerty',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user