I'm trying to follow the instructions here to customize Oauth with Azure AD:

https://docs.statamic.com/oauth#customization

and

https://docs.statamic.com/addons/classes/event-listeners

The default version of Oauth works great with Azure, however if a user is not logged in to Statamic the first time they authenticate, it creates a new user in Statamic and we don't want that. Everyone already has a Statamic account, so I am trying to get Statamic to search for users by email address instead of making new users. I'm not sure if it isn't working because I don't have the Listener code correct or because the code I copied from Socialite to get the user email is wrong. Any advice?

Here's my OauthBridgeListener.php:

<?php

namespace Statamic\Addons\OAuthBridge;

use Statamic\Extend\Listener;

class OAuthBridgeListener extends Listener
{
    /**
     * The events to be listened for, and the methods to call.
     *
     * @var array
     */
    public $events = ['Statamic\Addons\OAuthBridge\FindingUser' => 'findUser'];

    public function findUser(FindingUser $event)
    {
        if ($event->provider !== 'azure') {
            return; // Returning nothing will make Statamic continue as per usual.
        }

        // create a user ...
        // the following is the customized part

        //can we use the $provider_user variable
        $email = Socialite::driver('azure')->getEmail();
        $user = User::whereEmail($email); // Returns User



        //the following returns to the "shell" provided by instructions
        return $user;
    }
}