Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lxg's avatar
Level 1

Azure AD Authentication in my Laravel Web App

Hey guys,

I am trying to add Authentication with Azure AD to my Laravel Web Application, hosted on IIS. I followed the instructions in the following Link as precise as possible: https://github.com/Azure-Samples/active-directory-b2c-php-webapp-openidconnect I don't have acces to the policys so i had to remove the policy_name in the getMetadata Function in the Endpointhandler

public function getMetadata($policy_name) {
        require "settings.php";
        $metadata_endpoint = $metadata_endpoint_begin; // . $policy_name;
        $this->metadata = $this->getEndpointData($metadata_endpoint);
    }

After i did everything in the instructions in the Link above and placed a Login-Button, which calls this function...

 public function login()
    {


        require app_path()."/Http/Controllers/settings.php";
        require app_path()."/Http/Controllers/EndpointHandler.php";

        // Set cookie for state
        $state = rand();
        setcookie("state", $state);

        // Redirect to sign up/sign in page
        $endpoint_handler = new EndpointHandler($generic_policy);

        $authorization_endpoint = $endpoint_handler->getAuthorizationEndpoint()."&state=generic"."+". $state;
        return redirect($authorization_endpoint);
    }

...I am getting this error when clicking the Button

Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_UNKNOWN) Cannot redeclare getClaim() (previously declared in C:\inetpub\wwwroot\bcompetent\fleet_booking_test\app\Http\Controllers\EndpointHandler.php:6)

when i place "namespace App\Http\Controllers"; on top of the EndpointHandler.php and the TokenChecker.php i don't get this Error anymore and i get directed to this Link:

https://login.microsoftonline.com/ef7e48cb-7676-47e9-9a28-c69910d92560/oauth2/v2.0/authorize?response_type=id_token&client_id=3a0621c0-2848-47f5-83ee-bebeede8aaa6&redirect_uri=https%3A%2F%2Fbcompetent.bertrandt.com%2Ffleetbookingtest%2Fpublic&response_mode=form_post&scope=openid&nonce=c78c18a3-7ad7-4c17-a469-00fdadf35a3e&state=generic+861376380

where i can enter my Login-credentials, but after i did this i am getting the Error

Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR) Class 'App\Http\Controllers\Crypt_RSA' not found

Does anyone here have a Solution for my Problem? I have a feeling that it could have something to do with composer or with the providers in my config/app.php but i am just guessing, because i am very new to Laravel.

I am thankful for every kind of assistance

0 likes
6 replies
lxg's avatar
Level 1

@MTHOMAS - The reason is that i am very new to this topic and very unexperienced.. i will have a look at this stuff. Thank you very much :)

MThomas's avatar

@lxg Most of the time there will be package for such a feature.

Good luck!

fahadshafique786's avatar

Hi, Dear can you please tell me which one is best package for SSO integration with Azure Active Directory. Please help to find out because I'm the new one on it. I'll be very thankful to you.

Kryll's avatar

I have the same needs.

I have an application in Symfony 5 and with the thenetworg/oauth2-azure component. This application works (locally and in production). I have the Client_ID, Client_Secret, Tenant_ID and a callback URL.

But I haven't found anything that works with the fresh Laravel 7, I tested Socialite without success.

Do you have any leads?

1 like

Please or to participate in this conversation.