-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost-saml.php
More file actions
44 lines (33 loc) · 1.48 KB
/
post-saml.php
File metadata and controls
44 lines (33 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
include "inc.php";
include "src/Utility/IdpProvider.php";
include "src/Utility/IdpTools.php";
// Initiating our IdP Provider dummy connection.
$idpProvider = new IdpProvider();
// Instantiating our Utility class.
$idpTools = new IdpTools();
// Receive the HTTP Request and extract the SAMLRequest.
$request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
$saml_request = $idpTools->readSAMLRequest($request);
// Getting a few details from the message like ID and Issuer.
$issuer = $saml_request->getMessage()->getIssuer()->getValue();
$id = $saml_request->getMessage()->getID();
// Simulate user information from IdP
$user_id = $request->get("username");
$user_email = $idpProvider->getUserEmail();
// Construct a SAML Response.
$response = $idpTools->createSAMLResponse($idpProvider, $user_id, $user_email, $issuer, $id);
//die();
// Prepare the POST binding (form).
$bindingFactory = new \LightSaml\Binding\BindingFactory();
$postBinding = $bindingFactory->create(\LightSaml\SamlConstants::BINDING_SAML2_HTTP_POST);
$messageContext = new \LightSaml\Context\Profile\MessageContext();
$messageContext->setMessage($response);
// Ensure we include the RelayState.
$message = $messageContext->getMessage();
$message->setRelayState($request->get('RelayState'));
$messageContext->setMessage($message);
// Return the Response.
/** @var \Symfony\Component\HttpFoundation\Response $httpResponse */
$httpResponse = $postBinding->send($messageContext);
print $httpResponse->getContent();