Integrating custom SSO client logic into Pyro's login process
Created 5 years ago by dxtrsHey all
I'm trying to integrate a Laravel SSO package (jasny/sso) into Pyro's login process and have the Pyro installation act as a client. I've already created the SSO server (we'll be using our own one) and two dummy clients in Laravel to test and they work.
The integration happened in the LoginController.php. So in Pyro I was trying to override the login controller in order to add functionality upon login. I need to get the request()->get('email')
and request()->get('password')
but they're null when the request happens. Upon further investigation, I didn't see a POST request to /login
when I inspect the traffic - instead I saw that the action on the login form was to form/handle/{key}
- how does that work and how can I then inject my own logic into the login process?
I am following the example for the client and server logic from the Github page https://github.com/awnali/SSO-laravel-5.
I look forward to and appreciate anyone's help,
Thanks for the feedback Ryan - much appreciated.
I like the first option. When you say "on the builder", which builder and how do I get access to it in a service provider? Could you please provide a small snippet?
Are there login success and failure events that I could hook into? Is there a list of events somewhere I could look at?
Thanks,
@dxtrs you would use the LoginFormBuilder
. Here's a better code example:
<?php namespace Anomaly\NewishTheme;
use Anomaly\Streams\Platform\Addon\AddonServiceProvider;
use Anomaly\UsersModule\User\Login\LoginFormBuilder;
class NewishThemeServiceProvider extends AddonServiceProvider
{
/**
* Boot the addon.
*/
public function boot(LoginFormBuilder $builder)
{
$builder->on(
'posting',
function () use ($builder) {
if ($builder->getFormValue('email') == request('email')) {
dd('Yes!');
}
// Do stuff..
}
);
}
}
@ryanthompson Should I be using an AddonServiceProvider or could I use a normal ServiceProvider? When I use the latter, the 'posting' event doesn't seem to trigger upon login submit.
If I need to use the former, do I create the AddonServiceProvider with the Artisan command and have all that boilerplate?
Thanks Ryan,
@ryanthompson Thanks for the help Ryan. I've created an AddonServiceProvider and included it in my theme's DefaultThemeServiceProvider's $providers
array. But I get the error: Type error: Too few arguments to function Anomaly\Streams\Platform\Addon\AddonServiceProvider::__construct(), 1 passed in /var/www/sbt.local/vendor/laravel/framework/src/Illuminate/Foundation/Application.php on line 635 and exactly 2 expected
. Am I including it correctly?
@ryanthompson Thanks for the help Ryan. I've created an AddonServiceProvider and included it in my theme's DefaultThemeServiceProvider's $providers
array. But I get the error: Type error: Too few arguments to function Anomaly\Streams\Platform\Addon\AddonServiceProvider::__construct(), 1 passed in /var/www/sbt.local/vendor/laravel/framework/src/Illuminate/Foundation/Application.php on line 635 and exactly 2 expected
. Am I including it correctly?
@ryanthompson Thanks for the help Ryan. I've created an AddonServiceProvider and included it in my theme's DefaultThemeServiceProvider's $providers
array. But I get the error: Type error: Too few arguments to function Anomaly\Streams\Platform\Addon\AddonServiceProvider::__construct(), 1 passed in /var/www/sbt.local/vendor/laravel/framework/src/Illuminate/Foundation/Application.php on line 635 and exactly 2 expected
. Am I including it correctly?
So there are a couple ways you can tackle this:
Callbacks:
You could add an
onPosting
callback on the builder from a theme service provider or something. Inject the login form$builder
and use something like the following (or other trigger likeready
or something).You can also override the form entirely by extending it with one of your own - and binding it to
my.login_form
or something in your service provider's$bindings
property. You would need to make sure any handlers or classes surrounding the original LoginFormBuilder though have stuff manually listed likeprotected $handler = LoginFormHandler::class
since they're no longer next to each other.