What is the best way to use Aura.Auth with multiple providers?

46 views
Skip to first unread message

Shameer C

unread,
Dec 29, 2014, 10:52:41 PM12/29/14
to aur...@googlegroups.com
Hi

I'm trying to setup Aura.Auth with direct login and social sign in as well, but I'm facing problems when wiring things up. I got it working with just Facebook or direct login only. But when there is multiple providers I find it difficult to implement the Logout action. I have different login URL for each provider and a logout URL for all. Like,

/auth/login
/auth/login/facebook
/auth/login/github

/auth/logout


In the application I've to pass aura:auth/login_service, aura:auth/logout_service and aura:auth/resume_service to the Auth. All of these services expect the adapter as a parameter. So I've to create adapter object to each provider and pass them to each service.

$di->set('facebookadapter', $di->lazyNew('MyApp\Auth\LeagueOAuth2Adapter',
            ['provider' => $di->lazyGet('facebookAuthProvider')]
        ));
$di->set('aura/auth:pdo_adapter', $di->lazyNew('Aura\Auth\Adapter\PdoAdapter'));

$di->set('facebookLoginService', $di->lazyNew('Aura\Auth\Service\LoginService', [
            'adapter' => $di->lazyGet('facebookadapter'),
            'session' => $di->lazyGet('aura/auth:session')
        ]));
$di->set('facebook_auth_service', $di->lazyNew('MyApp\Domain\Service\AuthService', [
            'auth' => $di->lazyGet('aura/auth:auth'),
            'login_service' => $di->lazyGet('facebookLoginService'),
            'resume_service' => $di->lazyGet('aura/auth:resume_service'),
            'logout_service' => $di->lazyGet('aura/auth:logout_service')
        ]));

$di->params['MyApp\Action\User\FacebookLoginAction'] = [
            'request' => $di->lazyGet('aura/web-kernel:request'),
            'auth_service' => $di->get('facebook_auth_service'),
            'user_service' => $di->lazyNew('MyApp\Domain\Service\UserService'),
            'responder' => $di->lazyNew('MyApp\Responder\UserLoginResponder')
        ];

and so on..

This will work when I'm using different action for different auth provider, but is difficult to manage in the case of logout where there is only one action and I'm passing only one auth_service object

$di->params['MyApp\Action\User\LogoutAction'] = [
            'request' => $di->lazyGet('aura/web-kernel:request'),
            'auth_service' => $di->get('auth_service') // or facebook_auth_service, pdo_auth_service
        ];

I hope my question is clear. Can anyone suggest what is the best way to manage this? Or am I over-complicating things?

Thanks in advance
Shameer

Brandon Savage

unread,
Dec 29, 2014, 11:06:32 PM12/29/14
to aur...@googlegroups.com
Why don't you just call forceLogout() on the LogoutService?

Brandon

--
You received this message because you are subscribed to the Google Groups "The Aura Project for PHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to auraphp+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hari K T

unread,
Dec 29, 2014, 11:25:13 PM12/29/14
to aur...@googlegroups.com
I think one of the problem is you don't know which adapter the user have used. 

May be we can save that in a session and remove based on that ? But that is really a hack and may be it should be an array of adapters for sometimes people want to link between different login.

Hari K T

You can ring me : +91 9388 75 8821

Skype  : kthari85
Twitter : harikt

Brandon Savage

unread,
Dec 29, 2014, 11:40:53 PM12/29/14
to aur...@googlegroups.com
Regardless, the only reason you might have to use the LogoutService::logout() method is if the adapter has some special action it needs to take for logout. That method is implemented but empty in the AbstractAdapter class. LogoutService::forceLogout() will kill the user's login sufficiently if you don't need to do anything with the adapter.

Brandon

Shameer C

unread,
Dec 30, 2014, 12:32:10 AM12/30/14
to aur...@googlegroups.com
Thanks Brandon, Hari! That did work. So my AuthService:logout() should call LogoutService::forceLogout().

Do you have any other suggestions on the implementation? I feel it's a lot of works to do from the user side, simply because the login/resume/logout_service requires adapter. It will be much better if we don't have to worry about these services, but Auth itself can handle them.

Cheers
Shameer
Shameer C
@shameerc | +91-9747 377 001

Hari K T

unread,
Dec 30, 2014, 12:34:30 AM12/30/14
to aur...@googlegroups.com
Hey Shameer, 

As you pointed to the example https://github.com/cocoframework/Cocoframework.Example/blob/master/src/AuthService.php#L52-L55 see the lines. It already have those methods :) .

So I assume you have less work on it.

Or did I missed something?

Hari K T

You can ring me : +91 9388 75 8821

Skype  : kthari85
Twitter : harikt

Hari K T

unread,
Dec 30, 2014, 12:37:17 AM12/30/14
to aur...@googlegroups.com
Thanks Brandon, Hari! That did work. So my AuthService:logout() should call LogoutService::forceLogout().

Do you have any other suggestions on the implementation? I feel it's a lot of works to do from the user side, simply because the login/resume/logout_service requires adapter. It will be much better if we don't have to worry about these services, but Auth itself can handle them.

I agree with you. I too have a feeling there should be some simple ways than asking the user to do all. Currently lots of configuration and it takes most of the time than writing code is an issue I am seeing . I don't disagree with it.

Shameer C

unread,
Dec 30, 2014, 1:06:50 AM12/30/14
to aur...@googlegroups.com
Yes, that Class helped me to get it done :)

Thanks
Shameer

--
You received this message because you are subscribed to the Google Groups "The Aura Project for PHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to auraphp+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hari K T

unread,
Dec 30, 2014, 2:18:49 AM12/30/14
to aur...@googlegroups.com
By the way I have added a chapter on authentication to the book https://leanpub.com/aurav2/read#leanpub-auto-authentication .

If you think there is something to improve please let me know.

Thanks!

Hari K T

You can ring me : +91 9388 75 8821

Skype  : kthari85
Twitter : harikt

Reply all
Reply to author
Forward
0 new messages