Showing posts with label cURL. Show all posts
Showing posts with label cURL. Show all posts

Thursday, May 4, 2023

Performing SAML Authentication Against Azure AD in Laravel Without the ext-http Extension

Yes, you can use cURL instead of the ext-http extension in Laravel to perform SAML authentication against Azure AD. Here's how you can do it:

  1. Install the LightSaml library in your Laravel application using Composer.
composer require lightsaml/lightsaml
  1. Use the cURL extension in PHP to send the SAML request to Azure AD.

Here's an example of how to use cURL to send a SAML request:

$url = 'https://login.microsoftonline.com/[tenant-id]/saml2'; $relayState = 'https://example.com/dashboard'; $id = '_' . sha1(uniqid('', true)); $issueInstant = gmdate('Y-m-d\TH:i:s\Z'); $samlRequest = '...'; // The SAML request XML $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => $url, CURLOPT_POST => true, CURLOPT_POSTFIELDS => http_build_query(array( 'SAMLRequest' => base64_encode($samlRequest), 'RelayState' => $relayState )), CURLOPT_HTTPHEADER => array( 'Content-Type: application/x-www-form-urlencoded', 'Content-Length: ' . strlen(http_build_query(array( 'SAMLRequest' => base64_encode($samlRequest), 'RelayState' => $relayState ))), 'Accept-Encoding: gzip, deflate', 'Accept-Language: en-US,en;q=0.9', 'Connection: keep-alive', 'Host: login.microsoftonline.com', 'Referer: https://example.com/login', 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36' )), CURLOPT_RETURNTRANSFER => true )); $response = curl_exec($curl); curl_close($curl);

 Parse the SAML response received from Azure AD using the LightSaml library.

Here's an example of how to use the LightSaml library to parse the SAML response:

$responseDom = new \DOMDocument(); $responseDom->loadXML($response); $deserializer = new \LightSaml\Model\Protocol\Response\SamlResponseDeserializer(); /** @var \LightSaml\Model\Protocol\Response\SamlResponse $response */ $response = $deserializer->deserialize($responseDom->documentElement);


 By following these steps, you can perform SAML authentication against Azure AD in Laravel without using the ext-http extension.






ASP.NET Core

 Certainly! Here are 10 advanced .NET Core interview questions covering various topics: 1. **ASP.NET Core Middleware Pipeline**: Explain the...