SAML Single Sign-On (SSO) For Laravel Using Azure B2C As IDP

SAML Single Sign-On (SSO) For Laravel Using Azure B2C As IDP


Laravel SAML Single Sign-On (SSO) plugin gives the ability to enable SAML Single Sign-On for your laravel applications. Using Single Sign-On you can use only one password to access your laravel application and services. Our plugin is compatible with all the SAML compliant Identity providers. Here we will go through a step-by-step guide to configure Single Sign-On (SSO) between Laravel and Azure B2C considering Azure B2C as IdP.

Pre-requisites : Download And Installation

  • Open a Command Prompt window and change the working directory to your Laravel app's main directory.
  • Enter the below command.
    composer require miniorange/saml-laravel-free
  • Laravel Single Sign On SSO enter commond
  • Note: If you are using Laravel 5.4 or below, you will need to add the following value to the 'providers' array in your app.php file which can be found in the project\config folder :provider\ssoServiceProvider::class (You can check your current Laravel version by using the command php artisan --version.)

  • Laravel Single Sign On SSO add following value
  • After successful installation of package, go to your Laravel app in the browser and enter https://<your-host>/mo_admin in the address bar.
  • The package will start setting up your database for you and then redirect you to the admin registration page.
  • Register or log in with your account by clicking the Register button to configure the plugin.
  • Laravel Single Sign On SSO plugin settings
  • After login, you will see the Service Provider Settings option, where you will get the service provider metadata. Keep the metadata handy as it will be required later to configure step 1.
  • Laravel Single Sign On SSO Service Provider Settings

Steps to configure Azure B2C Single Sign-On (SSO) Login into Laravel

1. Configure Azure B2C as Identity Provider

    1.1 Register Azure B2C Applications

    miniorange img Register the Identity Experience Framework application
    • Login into Azure B2C Portal
    • From the Azure AD B2C tenant, select App registrations, and then select New registration.
    • Azure B2C  Laravel SSO - Azure Single Sign-On(SSO) Login in  Laravel- portal
    • For Name, enter IdentityExperienceFramework.
    • Under Supported account types, select Accounts in this organizational directory only.
    • Azure B2C  Laravel SSO - Azure Single Sign-On(SSO) Login in  Laravel - Register an Application
    • Under Redirect URI, select Web, and then enter https://your-tenant-name.b2clogin.com/your-tenant-name.onmicrosoft.com, where your-tenant-name is your Azure AD B2C tenant domain name.
    • NOTE:

      In the following step if the 'Permissions' section is not visible then it might be the reason that you don't have an active AzureAD B2C subscription for that tenant. You can find the details regarding the AzureAD B2C subscription here and you can create a new tenant by following the steps here.


    • Under Permissions, select the Grant admin consent to openid and offline_access permissions check box.
    • Select Register.
    • Azure B2C  Laravel SSO - Azure Single Sign-On(SSO) Login in  Laravel - Redirect URL
    • Record the Application (client) ID for use in a later step.
    • Azure B2C  Laravel SSO - Azure Single Sign-On(SSO) Login in  Laravel - Application Client ID
    miniorange img Register the Identity Experience Framework application
    • Under Manage, select Expose an API.
    • Select Add a scope, then select Save and continue to accept the default application ID URI.
    • Azure B2C  Laravel SSO - Azure Single Sign-On(SSO) Login in  Laravel - Expose an api
    • Enter the following values to create a scope that allows custom policy execution in your Azure AD B2C tenant:
      1. Scope name: user_impersonation
      2. Admin consent display name: Access IdentityExperienceFramework
      3. Admin consent description: Allow the application to access IdentityExperienceFramework on behalf of the signed-in user.
    • Select Add scope
    • Azure B2C  Laravel SSO - Azure Single Sign-On(SSO) Login in  Laravel - custom scopes
    miniorange img Register the ProxyIdentityExperienceFramework application
    • Select App registrations, and then select New registration.
    • For Name, enter ProxyIdentityExperienceFramework.
    • Under Supported account types, select Accounts in this organizational directory only.
    • Azure B2C  Laravel SSO - Azure Single Sign-On(SSO) Login in  Laravel - Original Directory
    • Under Redirect URI, use the drop-down to select Public client/native (mobile & desktop).
    • For Redirect URI, enter myapp://auth.
    • Under Permissions, select the Grant admin consent to openid and offline_access permissions check box.
    • Select Register.
    • Azure B2C  Laravel SSO - Azure Single Sign-On(SSO) Login in  Laravel - Register
    • Record the Application (client) ID for use in a later step.
    • Azure B2C WordPress SSO - Azure Single Sign-On(SSO) Login in WordPress -  application proxy
    miniorange img Next, specify that the application should be treated as a public client
    • Under Manage, select Authentication.
    • Under Advanced settings, enable Allow public client flows (select Yes).
    • Select Save.
    • Azure B2C  Laravel SSO - Azure Single Sign-On(SSO) Login in  Laravel - proxy authentication
    miniorange img Now, grant permissions to the API scope you exposed earlier in the IdentityExperienceFramework registration
    • Under Manage, select API permissions.
    • Under Configured permissions, select Add a permission.
    • Azure B2C  Laravel SSO - Azure Single Sign-On(SSO) Login in  Laravel - authentication
    • Select the My APIs tab, then select the IdentityExperienceFramework application.
    • Azure B2C  Laravel SSO - Azure Single Sign-On(SSO) Login in  Laravel - API permissions
    • Under Permission, select the user_impersonation scope that you defined earlier.
    • Select Add permissions. As directed, wait a few minutes before proceeding to the next step.
    • Azure B2C  Laravel SSO - Azure Single Sign-On(SSO) Login in  Laravel- My APIs
    • Select Grant admin consent for (your tenant name).
    • Azure B2C  LaravelSSO - Azure Single Sign-On(SSO) Login in  Laravel - Grant Admin
    • Select your currently signed-in administrator account, or sign in with an account in your Azure AD B2C tenant that's been assigned at least the Cloud application administrator role.
    • Select Yes.
    • Select Refresh, and then verify that "Granted for ..." appears under Status for the scopes - offline_access, openid and user_impersonation. It might take a few minutes for the permissions to propagate.
    • Azure B2C  LaravelSSO - Azure Single Sign-On(SSO) Login in  Laravel - B2C,Status og admin access
    miniorange img Register the WordPress Application
    • Select App registrations, and then select New registration.
    • Enter a Name for the application such as: WordPress.
    • Under Supported account types, select Accounts in any organizational directory or any identity provider. For authenticating users with Azure AD B2C.
    • Azure B2C  Laravel SSO - Azure Single Sign-On(SSO) Login in  Laravel- Supported account types
    • Under Redirect URI, select Web, and then enter the ACS URL from the Service Provider Metadata tab of the miniOrange SAML plugin.
    • Select Register.
    • Azure B2C  Laravel SSO - Azure Single Sign-On(SSO) Login in  Laravel - app Register
    • Under Manage, click on Expose an API.
    • Click on Set for the Application ID URI and then click on Save, accepting the default value.
    • SAML Single Sign-On (SSO) using Azure B2C as Identity Provider (IdP),for SAML 2.0 Azure B2C,WP-app Expose a sso login
    • Once saved, copy the Application ID URI and paste it into the SP Entity ID / Issuer field under the laravel saml plugin.
    • Click on Save.

    1.2 Generate SSO Policies

    • From our Azure B2C portal, navigate to the Overview section of your B2C tenant and record your tenant name.
      NOTE: If your B2C domain is b2ctest.onmicrosoft.com, then your tenant name is b2ctest.
    • Azure B2C  Laravel SSO - Azure Single Sign-On(SSO) Login in  Laravel - B2C tenant ID Reco
    • Enter your Azure B2C tenant name below, along with the application ID for IdentityExperienceFramework and
      ProxyIdentityExperienceFramework apps as registered in the above steps.

    • Azure B2C tenant Name:
      IdentityExperienceFramework app ID:
      ProxyIdentityExperienceFramework app ID:


    • Click on the Generate Azure B2C Policies button to download the SSO policies.
    • Extract the downloaded zip file. It contains the policy files and certificate (.pfx), which you will require in the following steps.

    1.3 Setup Certificates

    NOTE:

    In the following step if the 'Identity Experience Framework' is not clickable then it might be the reason that you don't have an active Azure AD B2C subscription for that tenant. You can find the details regarding the Azure AD B2C subscription here and you can create a new tenant by following the steps here.

    miniorange img Upload the Certificate
    • Sign in to the Azure portal and browse to your Azure AD B2C tenant.
    • Azure B2C  Laravel SSO - Azure Single Sign-On(SSO) Login in  Laravel- framework
    • Under Policies, select Identity Experience Framework and then Policy keys.
    • Azure B2C  Laravel SSO - Azure Single Sign-On(SSO) Login in Laravel - Policy keys
    • Select Add, and then select Options > Upload
    • Enter the Name as SamlIdpCert. The prefix B2C_1A_ is automatically added to the name of your key.
    • Azure B2C  Laravel SSO - Azure Single Sign-On(SSO) Login in Laravel- Create a Key
    • Using the upload file control, upload your certificate that was generated in the above steps along with the SSO policies (tenantname-cert.pfx).
    • Enter the certificate's password as your tenant name and click on Create. For example, if your tenant name is xyzb2c.onmicrosoft.com, enter the password as xyzb2c
    • You should be able to see a new policy key with the name B2C_1A_SamlIdpCert.
    miniorange img Create the signing key
    • On the overview page of your Azure AD B2C tenant, under Policies, select Identity Experience Framework.
    • Select Policy Keys and then select Add.
    • For Options, choose Generate.
    • In Name, enter TokenSigningKeyContainer.
    • For Key type, select RSA.
    • For Key usage, select Signature.
    • Azure B2C Laravel SSO - Azure Single Sign-On(SSO) Login in  Laravel - Create the signing key
    • Select Create.
    miniorange img Create the encryption key
    • On the overview page of your Azure AD B2C tenant, under Policies, select Identity Experience Framework.
    • Select Policy Keys and then select Add.
    • For Options, choose Generate.
    • In Name, enter TokenEncryptionKeyContainer.
    • For Key type, select RSA.
    • For Key usage, select Encryption.
    • Azure B2C Laravel SSO - Azure Single Sign-On(SSO) Login in  Laravel - Create the encryption key
    • Select Create.

    1.4 Upload the Policies

    • Select the Identity Experience Framework menu item in your B2C tenant in the Azure portal.
    • Azure B2C  Laravel SSO - Azure Single Sign-On(SSO) Login in WordPress - Upload the Policies
    • Select Upload custom policy.
    • Azure B2C  Laravel SSO - Azure Single Sign-On(SSO) Login in  Laravel - identity experience framework
    • As per the following order, upload the policy files downloaded in the above steps:
      • TrustFrameworkBase.xml
      • TrustFrameworkExtensions.xml
      • SignUpOrSignin.xml
      • ProfileEdit.xml
      • PasswordReset.xml
      • SignUpOrSigninSAML.xml
    • As you upload the files, Azure adds the prefix B2C_1A_ to each.

    You have successfully configured Azure B2C as SAML IdP (Identity Provider) for achieving WordPress Azure B2C Single Sign-On (SSO) Login, ensuring secure login into WordPress (WP) Site.

2. Configure Laravel SAML plugin as Service Provider

  • Go to the miniOrange Laravel SAML 2.0 SSO plugin and click on Choose File button next to the Upload Meatadata option.
  • Select the metadata file we downloaded from your IDP and click on Upload button.
  • Laravel Single Sign On SSO Identity Provider Settings
  • Click on Test Configuration button to test whether the SAML Configuration you've done is correct. On successful test configuration, you will get the different user attributes returned by your identity Provider in a test configuration table.
  • Laravel Single Sign On SSO Test Configuration Laravel Single Sign On SSO Test Result

3. SSO Options

  • Your users can initiate the Single Sign On flow by clicking on the Single Sign On button generated on your login page. If you do not have this page yet, run php artisan make:auth & php artisan migrate to generate the authentication module.

  • Laravel Single Sign On SSO Single Sign On button

In this Guide, you have successfully configured Azure B2C SAML Single Sign-On (Azure AD SSO Login) choosing Azure B2C as IdP and Laravel as SP using miniOrange plugin-SAML Single Sign On – SSO Login. This solution ensures that you are ready to roll out secure access to your Laravel site using Azure B2C login credentials within minutes.

Additional Resources

Hello there!

Need Help? We are right here!

support
Contact miniOrange Support
success

Thanks for your inquiry.

If you dont hear from us within 24 hours, please feel free to send a follow up email to info@xecurify.com