OpenID-2 in progress (#595)
This commit is contained in:
parent
e4bf8ac619
commit
7805387aff
|
@ -129,7 +129,7 @@
|
||||||
.\" ========================================================================
|
.\" ========================================================================
|
||||||
.\"
|
.\"
|
||||||
.IX Title "llng-fastcgi-server 1"
|
.IX Title "llng-fastcgi-server 1"
|
||||||
.TH llng-fastcgi-server 1 "2017-01-02" "perl v5.24.1" "User Contributed Perl Documentation"
|
.TH llng-fastcgi-server 1 "2017-01-05" "perl v5.24.1" "User Contributed Perl Documentation"
|
||||||
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
|
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
|
||||||
.\" way too many mistakes in technical documents.
|
.\" way too many mistakes in technical documents.
|
||||||
.if n .ad l
|
.if n .ad l
|
||||||
|
|
|
@ -50,8 +50,6 @@ has ua => (
|
||||||
|
|
||||||
# TODO : LWP options to use a proxy for example
|
# TODO : LWP options to use a proxy for example
|
||||||
my $ua = LWP::UserAgent->new();
|
my $ua = LWP::UserAgent->new();
|
||||||
push @{ $ua->requests_redirectable }, 'POST';
|
|
||||||
$ua->env_proxy();
|
|
||||||
return $ua;
|
return $ua;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -76,11 +76,11 @@ sub forUnauthUser {
|
||||||
return PE_OPENID_EMPTY;
|
return PE_OPENID_EMPTY;
|
||||||
}
|
}
|
||||||
if ( $mode eq 'associate' ) {
|
if ( $mode eq 'associate' ) {
|
||||||
return $self->_openIDResponse(
|
return $self->_openIDResponse( $req,
|
||||||
$self->openIDServer($req)->_mode_associate() );
|
$self->openIDServer($req)->_mode_associate() );
|
||||||
}
|
}
|
||||||
elsif ( $mode eq 'check_authentication' ) {
|
elsif ( $mode eq 'check_authentication' ) {
|
||||||
return $self->_openIDResponse(
|
return $self->_openIDResponse( $req,
|
||||||
$self->openIDServer($req)->_mode_check_authentication() );
|
$self->openIDServer($req)->_mode_check_authentication() );
|
||||||
}
|
}
|
||||||
return PE_OK;
|
return PE_OK;
|
||||||
|
@ -103,7 +103,7 @@ sub run {
|
||||||
return PE_ERROR;
|
return PE_ERROR;
|
||||||
}
|
}
|
||||||
my @r = $self->openIDServer($req)->_mode_checkid();
|
my @r = $self->openIDServer($req)->_mode_checkid();
|
||||||
return $self->_openIDResponse(@r);
|
return $self->_openIDResponse( $req, @r );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub logout {
|
sub logout {
|
||||||
|
@ -237,9 +237,7 @@ sub _openIDResponse {
|
||||||
else {
|
else {
|
||||||
$req->response(
|
$req->response(
|
||||||
$self->p->sendError(
|
$self->p->sendError(
|
||||||
$req,
|
$req, 'OpenID error ' . $self->openIDServer($req)->err()
|
||||||
'OpenID error ',
|
|
||||||
$self->openIDServer($req)->err()
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,13 +119,13 @@ sub display {
|
||||||
or $req->{error} == PE_OPENID_BADID )
|
or $req->{error} == PE_OPENID_BADID )
|
||||||
{
|
{
|
||||||
$skinfile = 'openid';
|
$skinfile = 'openid';
|
||||||
my $p = $self->{portal} . $self->{issuerDBOpenIDPath};
|
my $p = $self->conf->{portal} . $self->conf->{issuerDBOpenIDPath};
|
||||||
$p =~ s#(?<!:)/\^?/#/#g;
|
$p =~ s#(?<!:)/?\^?/#/#g;
|
||||||
%templateParams = (
|
%templateParams = (
|
||||||
AUTH_ERROR => $self->error,
|
AUTH_ERROR => $self->error,
|
||||||
AUTH_ERROR_TYPE => $req->error_type,
|
AUTH_ERROR_TYPE => $req->error_type,
|
||||||
PROVIDERURI => $p,
|
PROVIDERURI => $p,
|
||||||
ID => $self->{_openidPortal}
|
ID => $req->datas->{_openidPortal}
|
||||||
. $req->{sessionInfo}
|
. $req->{sessionInfo}
|
||||||
->{ $self->conf->{openIdAttr} || $self->conf->{whatToTrace} },
|
->{ $self->conf->{openIdAttr} || $self->conf->{whatToTrace} },
|
||||||
PORTAL_URL => $self->conf->{portal},
|
PORTAL_URL => $self->conf->{portal},
|
||||||
|
|
|
@ -7,7 +7,7 @@ BEGIN {
|
||||||
require 't/test-lib.pm';
|
require 't/test-lib.pm';
|
||||||
}
|
}
|
||||||
|
|
||||||
my $maintests = 4;
|
my $maintests = 7;
|
||||||
my $debug = 'debug';
|
my $debug = 'debug';
|
||||||
my ( $issuer, $sp, $res );
|
my ( $issuer, $sp, $res );
|
||||||
my %handlerOR = ( issuer => [], sp => [] );
|
my %handlerOR = ( issuer => [], sp => [] );
|
||||||
|
@ -33,18 +33,44 @@ SKIP: {
|
||||||
'Unauth SP request'
|
'Unauth SP request'
|
||||||
);
|
);
|
||||||
expectForm( $res, '#', undef );
|
expectForm( $res, '#', undef );
|
||||||
ok( $res->[2]->[0] =~ /name="openid_identifier"/, ' Found OpenID input' );
|
ok( $res->[2]->[0] =~ /name="openid_identifier"/,
|
||||||
|
' Ask for OpenID identity' );
|
||||||
|
|
||||||
my $query =
|
my $query =
|
||||||
'openid_identifier=http%3A%2F%2Fauth.idp.com%2Fopenidserver%2Fdwho';
|
'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);
|
ok(
|
||||||
|
$res = $sp->_post(
|
||||||
|
'/', IO::String->new($query),
|
||||||
|
length => length($query),
|
||||||
|
accept => 'text/html',
|
||||||
|
),
|
||||||
|
'Post OpenID identity'
|
||||||
|
);
|
||||||
|
my $uri;
|
||||||
|
( $uri, $query ) = expectRedirection( $res,
|
||||||
|
qr#http://auth.idp.com(/openidserver/?)\?(openid.*)$# );
|
||||||
|
|
||||||
|
# Follow redirection do IdP
|
||||||
|
switch ('issuer');
|
||||||
|
ok( $res = $issuer->_get( $uri, query => $query, accept => 'text/html' ),
|
||||||
|
'Follow redirection to IdP' );
|
||||||
|
expectOK($res);
|
||||||
|
my ( $host, $tmp );
|
||||||
|
( $host, $tmp, $query ) = expectForm( $res, '#', undef, 'openid.mode' );
|
||||||
|
$query .= '&user=dwho&password=dwho';
|
||||||
|
|
||||||
|
# Try to authenticate
|
||||||
|
ok(
|
||||||
|
$res = $issuer->_post(
|
||||||
|
$uri, IO::String->new($query),
|
||||||
|
length => length($query),
|
||||||
|
accept => 'text/html'
|
||||||
|
),
|
||||||
|
'Try to authenticate'
|
||||||
|
);
|
||||||
|
|
||||||
|
#print STDERR Dumper($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
count($maintests);
|
count($maintests);
|
||||||
|
@ -66,7 +92,6 @@ sub LWP::UserAgent::request {
|
||||||
my $url = $1;
|
my $url = $1;
|
||||||
my ($res);
|
my ($res);
|
||||||
count(1);
|
count(1);
|
||||||
print STDERR Dumper($req);
|
|
||||||
if ( $req->method =~ /^post$/i ) {
|
if ( $req->method =~ /^post$/i ) {
|
||||||
my $s = $req->content;
|
my $s = $req->content;
|
||||||
ok(
|
ok(
|
||||||
|
@ -74,24 +99,23 @@ sub LWP::UserAgent::request {
|
||||||
$url, IO::String->new($s),
|
$url, IO::String->new($s),
|
||||||
length => length($s),
|
length => length($s),
|
||||||
type => $req->header('Content-Type'),
|
type => $req->header('Content-Type'),
|
||||||
|
accept => 'text/plain',
|
||||||
),
|
),
|
||||||
' Execute request'
|
' Execute request'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ok( $res = $issuer->_get( $url, ), ' Execute request' );
|
ok( $res = $issuer->_get( $url, accept => 'text/plain', ),
|
||||||
|
' Execute post request' );
|
||||||
}
|
}
|
||||||
expectOK($res);
|
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' );
|
my $httpResp = HTTP::Response->new( $res->[0], 'OK' );
|
||||||
|
|
||||||
while ( my $name = shift @{ $res->[1] } ) {
|
while ( my $name = shift @{ $res->[1] } ) {
|
||||||
$httpResp->header( $name, shift( @{ $res->[1] } ) );
|
$httpResp->header( $name, shift( @{ $res->[1] } ) );
|
||||||
}
|
}
|
||||||
$httpResp->content( join( '', @{ $res->[2] } ) );
|
$httpResp->content( join( '', @{ $res->[2] } ) );
|
||||||
count(2);
|
count(1);
|
||||||
return $httpResp;
|
return $httpResp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,6 +145,9 @@ sub sp {
|
||||||
authentication => 'OpenID',
|
authentication => 'OpenID',
|
||||||
userDB => 'OpenID',
|
userDB => 'OpenID',
|
||||||
openIdSecret => 'qwerty',
|
openIdSecret => 'qwerty',
|
||||||
|
exportedVars => {
|
||||||
|
mail => 'email',
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -110,7 +110,7 @@ sub expectForm {
|
||||||
count(1);
|
count(1);
|
||||||
}
|
}
|
||||||
my %fields = ( $res->[2]->[0] =~
|
my %fields = ( $res->[2]->[0] =~
|
||||||
m#<input.+?name="(.+?)".+?value="(.+?)"#gs );
|
m#<input.+?name="(.+?)".+?value="(.*?)"#gs );
|
||||||
my $query = join( '&',
|
my $query = join( '&',
|
||||||
map { "$_=" . uri_escape( uri_unescape( $fields{$_} ) ) }
|
map { "$_=" . uri_escape( uri_unescape( $fields{$_} ) ) }
|
||||||
keys(%fields) );
|
keys(%fields) );
|
||||||
|
|
Loading…
Reference in New Issue
Block a user