2019-10-22 16:04:01 +02:00
|
|
|
use lib 'inc';
|
|
|
|
use Test::More;
|
|
|
|
use strict;
|
|
|
|
use IO::String;
|
|
|
|
use LWP::UserAgent;
|
|
|
|
use LWP::Protocol::PSGI;
|
|
|
|
use MIME::Base64;
|
|
|
|
|
|
|
|
BEGIN {
|
|
|
|
require 't/test-lib.pm';
|
2020-02-05 22:44:14 +01:00
|
|
|
require 't/oidc-lib.pm';
|
2019-10-22 16:04:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
my $debug = 'error';
|
|
|
|
my $res;
|
|
|
|
my $url;
|
|
|
|
|
|
|
|
# Initialization
|
|
|
|
ok( my $op = op(), 'OP portal' );
|
|
|
|
|
|
|
|
ok( $res = $op->_get('/oauth2/jwks'), 'Get JWKS, endpoint /oauth2/jwks' );
|
|
|
|
expectOK($res);
|
|
|
|
my $jwks = $res->[2]->[0];
|
|
|
|
|
|
|
|
ok(
|
|
|
|
$res = $op->_get('/.well-known/openid-configuration'),
|
|
|
|
'Get metadata, endpoint /.well-known/openid-configuration'
|
|
|
|
);
|
|
|
|
expectOK($res);
|
|
|
|
my $metadata = $res->[2]->[0];
|
|
|
|
|
|
|
|
my $query =
|
|
|
|
"response_type=code&scope=openid%20profile%20email&client_id=rpid&state=af0ifjsldkj&redirect_uri=http%3A%2F%2Frp.com%2F";
|
|
|
|
|
|
|
|
# Push request to OP
|
|
|
|
ok(
|
|
|
|
$res =
|
|
|
|
$op->_get( "/oauth2/authorize", query => $query, accept => 'text/html' ),
|
|
|
|
"Start Authorization Code flow"
|
|
|
|
);
|
|
|
|
expectOK($res);
|
|
|
|
|
|
|
|
# Try to authenticate to OP
|
|
|
|
$query = "user=french&password=french&$query";
|
|
|
|
ok(
|
|
|
|
$res = $op->_post(
|
|
|
|
"/oauth2/authorize",
|
|
|
|
IO::String->new($query),
|
|
|
|
accept => 'text/html',
|
|
|
|
length => length($query),
|
|
|
|
),
|
|
|
|
"Post authentication, endpoint $url"
|
|
|
|
);
|
|
|
|
my $idpId = expectCookie($res);
|
2019-12-16 17:52:45 +01:00
|
|
|
my ($code) = expectRedirection( $res, qr#http://rp.com/\?.*code=([^&]+)# );
|
2019-10-22 16:04:01 +02:00
|
|
|
|
|
|
|
# Get access token
|
|
|
|
$query =
|
|
|
|
"grant_type=authorization_code&code=$code&redirect_uri=http%3A%2F%2Frp.com%2F";
|
|
|
|
|
|
|
|
ok(
|
|
|
|
$res = $op->_post(
|
|
|
|
"/oauth2/token",
|
|
|
|
IO::String->new($query),
|
|
|
|
accept => 'text/html',
|
|
|
|
length => length($query),
|
|
|
|
custom => {
|
|
|
|
HTTP_AUTHORIZATION => "Basic " . encode_base64("rpid:rpsecret"),
|
|
|
|
},
|
|
|
|
),
|
|
|
|
"Post token"
|
|
|
|
);
|
|
|
|
|
|
|
|
my $tokenresp = JSON::from_json( $res->[2]->[0] );
|
|
|
|
ok( my $access_token = $tokenresp->{access_token}, 'Found access token' );
|
|
|
|
|
|
|
|
# Get Userinfo
|
|
|
|
ok(
|
|
|
|
$res = $op->_get(
|
|
|
|
"/oauth2/userinfo",
|
|
|
|
accept => 'text/html',
|
|
|
|
custom => {
|
|
|
|
HTTP_AUTHORIZATION => "Bearer " . $access_token,
|
|
|
|
},
|
|
|
|
),
|
|
|
|
"Post token"
|
|
|
|
);
|
|
|
|
|
|
|
|
my $userinfo = JSON::from_json( $res->[2]->[0] );
|
|
|
|
is( $userinfo->{family_name}, 'Accents', 'Correct macro value' );
|
2020-08-15 14:41:26 +02:00
|
|
|
is( $userinfo->{sub}, 'customfrench', 'Sub macro correctly evaluated' );
|
2019-10-22 16:04:01 +02:00
|
|
|
|
|
|
|
clean_sessions();
|
|
|
|
done_testing();
|
|
|
|
|
|
|
|
sub op {
|
|
|
|
return LLNG::Manager::Test->new( {
|
|
|
|
ini => {
|
|
|
|
logLevel => $debug,
|
|
|
|
domain => 'idp.com',
|
|
|
|
portal => 'http://auth.op.com',
|
|
|
|
authentication => 'Demo',
|
|
|
|
userDB => 'Same',
|
|
|
|
issuerDBOpenIDConnectActivation => 1,
|
|
|
|
issuerDBOpenIDConnectRule => '$uid eq "french"',
|
|
|
|
oidcRPMetaDataExportedVars => {
|
|
|
|
rp => {
|
|
|
|
email => "mail",
|
|
|
|
family_name => "extract_sn",
|
|
|
|
name => "cn"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
oidcServiceMetaDataAuthorizeURI => "authorize",
|
|
|
|
oidcServiceMetaDataCheckSessionURI => "checksession.html",
|
|
|
|
oidcServiceMetaDataJWKSURI => "jwks",
|
|
|
|
oidcServiceMetaDataEndSessionURI => "logout",
|
|
|
|
oidcServiceMetaDataRegistrationURI => "register",
|
|
|
|
oidcServiceMetaDataTokenURI => "token",
|
|
|
|
oidcServiceMetaDataUserInfoURI => "userinfo",
|
|
|
|
oidcServiceAllowHybridFlow => 1,
|
|
|
|
oidcServiceAllowImplicitFlow => 1,
|
|
|
|
oidcServiceAllowDynamicRegistration => 1,
|
|
|
|
oidcServiceAllowAuthorizationCodeFlow => 1,
|
2020-02-20 23:34:02 +01:00
|
|
|
oidcRPMetaDataMacros => {
|
2019-10-22 16:04:01 +02:00
|
|
|
rp => {
|
|
|
|
extract_sn => '(split(/\s/, $cn))[1]',
|
2020-08-15 14:41:26 +02:00
|
|
|
custom_sub => '"custom".$uid',
|
2019-10-22 16:04:01 +02:00
|
|
|
}
|
|
|
|
},
|
2020-02-20 23:34:02 +01:00
|
|
|
oidcRPMetaDataOptions => {
|
2019-10-22 16:04:01 +02:00
|
|
|
rp => {
|
|
|
|
oidcRPMetaDataOptionsDisplayName => "RP",
|
|
|
|
oidcRPMetaDataOptionsIDTokenExpiration => 3600,
|
|
|
|
oidcRPMetaDataOptionsClientID => "rpid",
|
|
|
|
oidcRPMetaDataOptionsIDTokenSignAlg => "HS512",
|
|
|
|
oidcRPMetaDataOptionsBypassConsent => 1,
|
|
|
|
oidcRPMetaDataOptionsClientSecret => "rpsecret",
|
2020-08-15 14:41:26 +02:00
|
|
|
oidcRPMetaDataOptionsUserIDAttr => "custom_sub",
|
2019-10-22 16:04:01 +02:00
|
|
|
oidcRPMetaDataOptionsAccessTokenExpiration => 3600,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
oidcOPMetaDataOptions => {},
|
|
|
|
oidcOPMetaDataJSON => {},
|
|
|
|
oidcOPMetaDataJWKS => {},
|
|
|
|
oidcServiceMetaDataAuthnContext => {
|
|
|
|
'loa-4' => 4,
|
|
|
|
'loa-1' => 1,
|
|
|
|
'loa-5' => 5,
|
|
|
|
'loa-2' => 2,
|
|
|
|
'loa-3' => 3
|
|
|
|
},
|
2020-02-05 22:44:14 +01:00
|
|
|
oidcServicePrivateKeySig => oidc_key_op_private_sig,
|
2020-02-20 23:34:02 +01:00
|
|
|
oidcServicePublicKeySig => oidc_key_op_public_sig,
|
2019-10-22 16:04:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|