You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: TUTORIAL.md
+91-96Lines changed: 91 additions & 96 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,26 +15,23 @@ In the case of Forwiki.org mentioned above it has a login function that is calle
15
15
The metadata is provided by the Identity Provider (IdP). Net::SAML2:IdP->new_from_url or Net::SAML2IdP->new_from_xml will take the metadata in the from specified and parse the metadata returning a Net::SAML2::IdP object
16
16
17
17
```
18
-
my $idp = Net::SAML2::IdP->new_from_url(
19
-
url => $metadata, # URL where the xml is located
20
-
cacert => $cacert, # Filename of the Identity Providers CACert
21
-
ssl_opts => # Optional options supported by LWP::Protocol::https
22
-
{
23
-
SSL_ca_file => '/your/directory/cacert.pem',
24
-
SSL_ca_path => '/etc/ssl/certs',
25
-
verify_hostname => 1,
26
-
}
27
-
28
-
);
29
-
```
18
+
my $idp = Net::SAML2::IdP->new_from_url(
19
+
url => $metadata, # URL where the xml is located
20
+
cacert => $cacert, # Filename of the Identity Providers CACert
21
+
ssl_opts => # Optional options supported by LWP::Protocol::https
22
+
{
23
+
SSL_ca_file => '/your/directory/cacert.pem',
24
+
SSL_ca_path => '/etc/ssl/certs',
25
+
verify_hostname => 1,
26
+
}
27
+
);
30
28
31
-
or
29
+
# or
32
30
33
-
```
34
-
my $idp = Net::SAML2::IdP->new_from_xml(
35
-
xml => $metadata_string, # xml as a string
36
-
cacert => $cacert, # Filename of the Identity Providers CACert
37
-
);
31
+
my $idp = Net::SAML2::IdP->new_from_xml(
32
+
xml => $metadata_string, # xml as a string
33
+
cacert => $cacert, # Filename of the Identity Providers CACert
34
+
);
38
35
```
39
36
40
37
The IdP object contains the Identity Providers settings that were parse from the metadata and are then used for the rest of the calls.
@@ -94,14 +91,14 @@ There are two methods to create the Authentication Request.
94
91
However, it is better to use new() here because it makes tracking the AuthnRequest ID easier for later verification.
95
92
96
93
```
97
-
my $authnreq = Net::SAML2::Protocol::AuthnRequest->new(
The **issuer** is the identifier that the web application uses to identify itself to the SAML2 Identity Provider. You will need to specify that identifier in the setup of your chosen Identity provider (GSuite, Azure, OneLogin, KeyCloak, etc)
@@ -113,16 +110,16 @@ The **destination** is set to the IdP's Single Sign-On Url that was parsed from
At this stage it is important for you to have the Service Provider SAML2 settings at the Identity Provider set correctly to match the values sent in the **AuthnRequest**
@@ -308,9 +305,9 @@ The security of SAML2 responses depends on trust in the Identity Provider. Trus
308
305
```
309
306
this results in:
310
307
```
311
-
$VAR1 = bless( {
312
-
'cacert' => 't/cacert.pem'
313
-
}, 'Net::SAML2::Binding::POST' );
308
+
$VAR1 = bless( {
309
+
'cacert' => 't/cacert.pem'
310
+
}, 'Net::SAML2::Binding::POST' );
314
311
```
315
312
316
313
### Handle the response
@@ -327,17 +324,17 @@ The handle_response() of the Net::SAML2::Binding::POST object processes the resp
327
324
328
325
handle_response is pretty short but does a couple of important things:
329
326
330
-
1. Calls XML::Sig to verify the signatures in the $saml_response XML
327
+
1. Calls Net::SAML2::XML::Sig (XML::Sig) to verify the signatures in the $saml_response XML
331
328
2. Verifies that the certificate that signed the XML was signed by the $cacert
332
329
333
330
### Get the Assertion from the SAMLResponse XML
334
331
335
332
The SAMLResponse is base64 encoded XML. The Net::SAML2::Protocol::Assertion->new_from_xml processes the full XML and create the Net::SAML2::Protocol::Assertion containing the assertion.
336
333
337
334
```
338
-
my $assertion = Net::SAML2::Protocol::Assertion->new_from_xml(
339
-
xml => decode_base64($saml_response)
340
-
);
335
+
my $assertion = Net::SAML2::Protocol::Assertion->new_from_xml(
336
+
xml => decode_base64($saml_response)
337
+
);
341
338
```
342
339
343
340
### Validating the Assertion
@@ -349,11 +346,11 @@ As it is a point in time assertion, you need to verify the validity of the NotBe
349
346
For the $saml_request_id you need to retrieve it from wherever it was stored during the creation of the Net::SAML2::Protocol::AuthnRequest. Foswiki.org SamlLoginContrib for instance had stored it in the user session.
350
347
351
348
```
352
-
my $issuer = $Foswiki::cfg{Saml}{issuer};
353
-
my $saml_request_id = $this->getAndClearSessionValue('saml_request_id');
349
+
my $issuer = $Foswiki::cfg{Saml}{issuer};
350
+
my $saml_request_id = $this->getAndClearSessionValue('saml_request_id');
354
351
355
-
# $assertion->valid() checks the dates and the audience
356
-
my $valid = $assertion->valid($issuer, $saml_request_id);
352
+
# $assertion->valid() checks the dates and the audience
353
+
my $valid = $assertion->valid($issuer, $saml_request_id);
357
354
```
358
355
359
356
The call to $assertion->valid validates the following for the assertion:
@@ -376,24 +373,24 @@ The nameid is the Identity Providers canonical userid that can be considered to
376
373
An example assertion attributes returned by GSuite could look like:
The assertion attributes are very specific to the combination of the Identity Provider and the SAML2 configuration. It can include any user specific values that can be accessed or transformed during the setup. It can also contain groups.
399
396
@@ -611,7 +608,6 @@ this results in the following XML
0 commit comments