2020-11-05 15:24:45 +01:00
|
|
|
use lib 'inc';
|
|
|
|
use Test::More;
|
|
|
|
use strict;
|
|
|
|
use IO::String;
|
|
|
|
use LWP::UserAgent;
|
|
|
|
use LWP::Protocol::PSGI;
|
|
|
|
use MIME::Base64;
|
|
|
|
use JSON;
|
|
|
|
|
|
|
|
BEGIN {
|
|
|
|
require 't/test-lib.pm';
|
|
|
|
require 't/oidc-lib.pm';
|
|
|
|
}
|
|
|
|
|
|
|
|
my $debug = 'error';
|
|
|
|
|
|
|
|
# Initialization
|
|
|
|
my $op = 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 => "cn",
|
|
|
|
name => "cn"
|
|
|
|
},
|
|
|
|
rp2 => {
|
|
|
|
email => "mail",
|
|
|
|
family_name => "cn",
|
|
|
|
name => "cn"
|
|
|
|
}
|
|
|
|
},
|
2021-01-28 15:06:19 +01:00
|
|
|
oidcRPMetaDataOptions => {
|
2020-11-05 15:24:45 +01:00
|
|
|
rp => {
|
|
|
|
oidcRPMetaDataOptionsDisplayName => "RP",
|
|
|
|
oidcRPMetaDataOptionsIDTokenExpiration => 3600,
|
|
|
|
oidcRPMetaDataOptionsClientID => "rpid",
|
|
|
|
oidcRPMetaDataOptionsIDTokenSignAlg => "HS512",
|
2021-01-28 15:06:19 +01:00
|
|
|
oidcRPMetaDataOptionsAccessTokenJWT => 1,
|
2020-11-05 15:24:45 +01:00
|
|
|
oidcRPMetaDataOptionsClientSecret => "rpsecret",
|
|
|
|
oidcRPMetaDataOptionsUserIDAttr => "",
|
|
|
|
oidcRPMetaDataOptionsAccessTokenExpiration => 3600,
|
|
|
|
oidcRPMetaDataOptionsBypassConsent => 1,
|
|
|
|
},
|
|
|
|
oauth => {
|
|
|
|
oidcRPMetaDataOptionsDisplayName => "oauth",
|
|
|
|
oidcRPMetaDataOptionsClientID => "oauth",
|
|
|
|
oidcRPMetaDataOptionsClientSecret => "service",
|
|
|
|
oidcRPMetaDataOptionsUserIDAttr => "",
|
|
|
|
}
|
|
|
|
},
|
|
|
|
oidcServicePrivateKeySig => oidc_key_op_private_sig,
|
|
|
|
oidcServicePublicKeySig => oidc_key_op_public_sig,
|
2021-01-14 15:31:36 +01:00
|
|
|
customPlugins => 't::OidcHookPlugin',
|
2020-11-05 15:24:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
my $res;
|
|
|
|
|
|
|
|
# Authenticate to LLNG
|
|
|
|
my $url = "/";
|
|
|
|
my $query = "user=french&password=french";
|
|
|
|
ok(
|
|
|
|
$res = $op->_post(
|
|
|
|
"/",
|
|
|
|
IO::String->new($query),
|
|
|
|
accept => 'text/html',
|
|
|
|
length => length($query),
|
|
|
|
),
|
|
|
|
"Post authentication"
|
|
|
|
);
|
|
|
|
my $idpId = expectCookie($res);
|
|
|
|
|
|
|
|
# Get code for RP1
|
|
|
|
$query =
|
|
|
|
"response_type=code&scope=openid%20profile%20email&client_id=rpid&state=af0ifjsldkj&redirect_uri=http%3A%2F%2Frp2.com%2F";
|
|
|
|
ok(
|
|
|
|
$res = $op->_get(
|
|
|
|
"/oauth2/authorize",
|
|
|
|
query => "$query",
|
|
|
|
accept => 'text/html',
|
|
|
|
cookie => "lemonldap=$idpId",
|
|
|
|
),
|
|
|
|
"Get authorization code"
|
|
|
|
);
|
|
|
|
|
|
|
|
my ($code) = expectRedirection( $res, qr#http://rp2\.com/.*code=([^\&]*)# );
|
|
|
|
|
|
|
|
# Exchange code for AT
|
|
|
|
$query =
|
|
|
|
"grant_type=authorization_code&code=$code&redirect_uri=http%3A%2F%2Frp2.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 $json = from_json( $res->[2]->[0] );
|
|
|
|
my $token = $json->{access_token};
|
|
|
|
ok( $token, 'Access token present' );
|
|
|
|
my $id_token = $json->{id_token};
|
|
|
|
ok( $id_token, 'ID token present' );
|
|
|
|
my $id_token_payload = id_token_payload($id_token);
|
2021-01-14 15:31:36 +01:00
|
|
|
is( $id_token_payload->{id_token_hook}, 1, "Found hooked claim in ID token" );
|
2020-11-05 15:24:45 +01:00
|
|
|
|
|
|
|
# Get userinfo
|
|
|
|
$res = $op->_post(
|
|
|
|
"/oauth2/userinfo",
|
|
|
|
IO::String->new(''),
|
|
|
|
accept => 'application/json',
|
|
|
|
length => 0,
|
|
|
|
custom => {
|
|
|
|
HTTP_AUTHORIZATION => "Bearer " . $token,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
$json = expectJSON($res);
|
2021-01-14 15:31:36 +01:00
|
|
|
is( $json->{userinfo_hook}, 1, "Found hooked claim in Userinfo token" );
|
2020-11-05 15:24:45 +01:00
|
|
|
|
2021-01-28 15:06:19 +01:00
|
|
|
expectJWT( $token, access_token_hook => 1 );
|
|
|
|
|
2020-11-05 15:24:45 +01:00
|
|
|
# Introspect to find scopes
|
|
|
|
$query = "token=$token";
|
|
|
|
ok(
|
|
|
|
$res = $op->_post(
|
|
|
|
"/oauth2/introspect",
|
|
|
|
IO::String->new($query),
|
|
|
|
accept => 'text/html',
|
|
|
|
length => length $query,
|
|
|
|
custom => {
|
|
|
|
HTTP_AUTHORIZATION => "Basic " . encode_base64("oauth:service"),
|
|
|
|
},
|
|
|
|
),
|
|
|
|
"Post introspection"
|
|
|
|
);
|
|
|
|
|
|
|
|
expectOK($res);
|
|
|
|
$json = from_json( $res->[2]->[0] );
|
2021-01-14 15:31:36 +01:00
|
|
|
like( $json->{scope}, qr/\bmy_hooked_scope\b/, "Found hook defined scope" );
|
|
|
|
like( $json->{scope}, qr/\bmyscope\b/, "Found result of oidcResolveScope" );
|
2020-11-05 15:24:45 +01:00
|
|
|
|
|
|
|
clean_sessions();
|
|
|
|
done_testing();
|
|
|
|
|