Using aimeos with sentinel (another authentication system)

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
aaronegger
Posts: 3
Joined: 11 May 2020, 01:17

Using aimeos with sentinel (another authentication system)

Post by aaronegger » 11 May 2020, 02:03

Hello,

i am very new to aimeos. We have currently a site based on Laravel 6 and installed the lts version of aimeos (2019.10).
To make things easy we decided to install the demo shop and customize it.
The installer mentions how to setup the whole site and how to get an admin account and how to extend the authservice provider.

Since we are using srlabs/centaur (an wrapper for sentinel -> an authentication system) we try to get aimeos working with that.
Sentinel has a role based permission system. We already have an front/backend implemented we would like to stay with this.

I used the config to implement custom authentication middlewares. The middlewares are working for all pages expect the admin page. It seems that the authentication at the admin page can not be overriden by a middleware. Is this correct?


But the biggest problem we have is that we now have two users table.

Is the a possibility to install the shop using the existing user managment system?

User avatar
aimeos
Administrator
Posts: 7889
Joined: 01 Jan 1970, 00:00

Re: Using aimeos with sentinel (another authentication system)

Post by aimeos » 11 May 2020, 17:38

Yes, it's possible. You have to replace the code in the boot() method of your app/Providers/AuthServiceProvider.php with your own code that checks agains your role based system. The Laravel code in the Aimeos admin controller will test for roles "super" (access to everything), "admin" and "editor": https://github.com/aimeos/aimeos-larave ... er.php#L38

To use the another table or external system for user data, you have to implement your own customer manager like the one for Laravel: https://github.com/aimeos/ai-laravel/bl ... aravel.php
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

aaronegger
Posts: 3
Joined: 11 May 2020, 01:17

Re: Using aimeos with sentinel (another authentication system)

Post by aaronegger » 13 May 2020, 16:46

Thank you for your answer.
I already stuck at overriding the boot method.
I have no idea how to override the auth process of laravel.
As far as i can see the role check will not be executed because aimeos is checking if the user is logged in.
But since the user is logged in via sentinel and not the native laravel auth system i get a redirect to the login page.
The first redirect seems to appear at the AdminController at the indexAction. There is an Auth::check call that returns false.

Did i miss something or do i have to override every controller that uses laravels native auth system?

User avatar
aimeos
Administrator
Posts: 7889
Joined: 01 Jan 1970, 00:00

Re: Using aimeos with sentinel (another authentication system)

Post by aimeos » 14 May 2020, 17:16

You only have to implement your own boot() method and overwrite the AdminController. The rest will automatically work if your boot() methods returns true/false depending on the permissions:

Code: Select all

    public function boot()
    {
        // Keep the lines before

        Gate::define('admin', function($user, $class, $roles) {
            // this is for checking super user previleges
            if( $user->superuser ) {
                return true;
            }
            // this is for checking user roles ("admin", "editor" and "api")
            return hasRole( $user, $roles );
        });
    }
    
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

aaronegger
Posts: 3
Joined: 11 May 2020, 01:17

Re: Using aimeos with sentinel (another authentication system)

Post by aaronegger » 20 May 2020, 11:31

Thanks for your anwser and your efforts.
But there are to many questions left that would cost too much time.
Especially replacing the customer manager seems to be a huge workload.
We are switching to vanilo.

Post Reply