Skip to content

Commit a2ff662

Browse files
committed
Allow custom config.yml file per Identity Provider
1 parent 4bf230a commit a2ff662

File tree

4 files changed

+39
-11
lines changed

4 files changed

+39
-11
lines changed

xt/testapp/README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,39 @@ Note that the command requires sudo to allow it to use the default https port of
4242

4343
TODO: maybe change it to use 8443
4444

45-
### Create your metadata.xml and cacert.pem file
45+
### Configure the testapp to connect to the Identity Provider
4646

4747
The testapp now supports a simplified automatic configuration for testing against multiple Identity Providers (IdPs).
4848

4949
1. Simply create a directory in xt/testapp/IdPs for the name of the IdP (eg. google)
5050
2. Download the metadata from your IdP and save it as IdPs/google/metadata.xml
5151
3. Download the cacert.pem from the IdP and save it as IdPs/google/cacert.pem
52+
4. Optionally create IdPs/google/config.yml for custom settings for the IdP (if the a custom config.yml does not exist it will refresh the settings from the default config.yml.
5253

5354
The index page will automatically list each configured Identity Provider as a link to initiate login against that IdP.
5455

56+
Your directory structure should look like:
57+
58+
IdPs/
59+
auth0/
60+
cacert.pem
61+
metadata.yml
62+
azure/
63+
cacert.pem
64+
config.yml (optional)
65+
metadata.yml
66+
google/
67+
cacert.pem
68+
metadata.yml
69+
5570
### Run lighttpd to deliver metadata.xml
5671

5772
Net::SAML2 requires access to a URL containing the metadata. The simplest method to provide this is to run the provided lighttpd-metadata.conf file:
5873

5974
1. cd xt/testapp
6075
2. lighttpd -D -f lighttpd-metadata.conf
6176

62-
The metadata has been configured to be available at: http://localhost:8880/metadata.xml. The simplified IdP configuration will automatically access the metadata.xml at http://localhost:8880/IdPs/googlee/metadata.xml (if you followed the instructions above and created the google directory in xt/testapp/IdPs)
77+
The metadata has been configured to be available at: http://localhost:8880/metadata.xml. The simplified IdP configuration will automatically access the metadata.xml at http://localhost:8880/IdPs/google/metadata.xml (if you followed the instructions above and created the google directory in xt/testapp/IdPs)
6378

6479
Note that the configuration attempts to only deliver a file named metadata.xml from the xt/testapp directory. There are no guarantees - this is a test application so verify your own security.
6580

xt/testapp/config.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ layout: "main"
33
appname: "Saml2Test"
44
charset: "UTF-8"
55
template: "template_toolkit"
6-
idp: "http://localhost:8880/metadata.xml"
76
issuer: "https://netsaml2-testapp.local"
87
url: "https://netsaml2-testapp.local"
98
cert: "sign-certonly.pem"
109
key: "sign-nopw-cert.pem"
11-
cacert: "saml_cacert.pem"
1210
slo_url_soap: "/slo-soap"
1311
slo_url_redirect: "/sls-redirect-response"
1412
slo_url_post: "/sls-post-response"

xt/testapp/lib/Saml2Test.pm

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,21 @@ get '/' => sub {
4747
};
4848

4949
get '/login' => sub {
50-
my $tokens = shift;
5150

5251
config->{cacert} = 'IdPs/' . params->{idp} . '/cacert.pem';
5352
config->{idp} = 'http://localhost:8880/IdPs/' . params->{idp} . '/metadata.xml';
53+
if ( -f 'IdPs/' . params->{idp} . '/config.yml' ) {
54+
my $config_file = YAML::LoadFile('IdPs/' . params->{idp} . '/config.yml');
55+
for my $key (keys %$config_file) {
56+
config->{$key} = $config_file->{$key};
57+
}
58+
} else {
59+
my $config_file = YAML::LoadFile('config.yml');
60+
for my $key (keys %$config_file) {
61+
config->{$key} = $config_file->{$key};
62+
}
63+
64+
}
5465
my $idp = _idp();
5566
my $sp = _sp();
5667
my $authnreq = $sp->authn_request(

xt/testapp/lighttpd.conf

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
server.document-root = var.CWD + "/"
22
server.modules = (
33
"mod_openssl",
4+
"mod_rewrite",
45
"mod_proxy"
56
)
67

@@ -34,9 +35,12 @@ setenv.add-environment = ("PATH" => env.PATH )
3435
# request debugging - UNCOMMENT TO ENABLE
3536
debug.log-request-handling = "enable"
3637

37-
$HTTP["host"] == "netsaml2-testapp.local" {
38-
proxy.server = ( "" => ( (
39-
"host" => "127.0.0.1",
40-
"port" => 3000
41-
) ) )
42-
}
38+
url.rewrite-repeat = (
39+
"^/bin/login" => "/consumer-post",
40+
"^/bin/logout(.*)" => "/sls-redirect-response$1"
41+
)
42+
43+
proxy.server = ( "" => ( (
44+
"host" => "127.0.0.1",
45+
"port" => 3000
46+
) ) )

0 commit comments

Comments
 (0)