Skip to content

Conversation

evansims
Copy link
Member

@evansims evansims commented Apr 26, 2023

Changes

This PR implements a feature request by @elliottlawson to allow for easier customization of authorization parameters before a login redirect is issued.

This is implemented through a new event, Auth0\Laravel\Event\Stateful\LoginAttempting. Applications can hook into this event and use the setParameters() method of the event to define additional parameters to be issued with the login redirect.

Example usage:

<?php // app/Listeners/CustomLoginParameters.php

namespace App\Listeners;

use Auth0\Laravel\Event\Stateful\LoginAttempting;

final class CustomLoginParameters
{
    public function handle(LoginAttempting $event): void
    {
        $event->setParameters([
			'connection' => '...',
		]);
    }
}
<?php // app/Providers/EventServiceProvider.php

use Auth0\Laravel\Event\Stateful\LoginAttempting;
use App\Listeners\CustomLoginParameters;
use Illuminate\Support\Facades\Event;

public function boot(): void
{
    Event::listen(
        LoginAttempting::class,
        [CustomLoginParameters::class, 'handle']
    );
}

In the above example, the host application adds a custom event listener (app/Listeners/CustomLoginParameters.php) to listen for and respond to the new LoginAttempting event. In this case, a connection parameter is added to the request. The application's event service provider (app/Providers/EventServiceProvider.php) is also customized to register the new event listener, as required by Laravel.

References

Resolves #373

Testing

All tests passing.

Contributor Checklist

@evansims evansims added the Scope: Improvement Proposed improvements, or feature additions. label Apr 26, 2023
@evansims evansims added this to the Next Release milestone Apr 26, 2023
@evansims evansims marked this pull request as ready for review April 26, 2023 05:08
@evansims evansims requested a review from a team as a code owner April 26, 2023 05:08
@codecov
Copy link

codecov bot commented Apr 26, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (6f23b16) 100.00% compared to head (b929065) 100.00%.

Additional details and impacted files
@@             Coverage Diff             @@
##                main      #382   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
  Complexity       295       295           
===========================================
  Files             21        21           
  Lines            806       806           
===========================================
  Hits             806       806           
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/Http/Controller/Stateful/Login.php 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@evansims evansims mentioned this pull request Apr 26, 2023
@evansims evansims enabled auto-merge (squash) April 26, 2023 05:22
Copy link

@poovamraj poovamraj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@evansims evansims merged commit 9eb38df into main Apr 26, 2023
@evansims evansims deleted the improve/add-loginattempting-event branch April 26, 2023 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Improvement Proposed improvements, or feature additions.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Ability To Specify Connection During Login

2 participants