DirectoryTree / LdapRecord-Laravel

Multi-domain LDAP Authentication & Management for Laravel.
https://ldaprecord.com/docs/laravel/v3
MIT License
501 stars 53 forks source link

issue when using Inertia.js stack in Laravel Jetstream #212

Closed MuhammedAlkhudiry closed 3 years ago

MuhammedAlkhudiry commented 3 years ago

Describe the feature you'd like: I tried to use this package in a Inertia.js stack, but It seems from trying, and from the docs, the package only supports livewire/traditional blade authentication.

I wish you add support for Inertia.js stack in Laravel Jetstream or API-token authentication in general and if It is possible to use this package I hope you update the docs.

Thank you!

stevebauman commented 3 years ago

Hi @KMLX28,

This is definitely not the case, as I primarily use the InertiaJS stack of Jetstream with LdapRecord.

Can you share where you exactly got stuck?

MuhammedAlkhudiry commented 3 years ago

I got stuck with the authentication, I added this and $validated is true so it's connected and validated:

        Fortify::authenticateUsing(function ($request) {
            $validated = Auth::validate([
                'mail' => $request->email,
                'password' => $request->password
            ]);

            return $validated ? Auth::getLastAttempted() : null;
        });

The problem is when I call Auth::check() after validating I get false, and the session()->all() is empty. So the problem is that I get passed the validation but the logging in is not stateful or persistence.

As I understand SPAs depend on API tokens and when I use User model from LdapRecord I don't think I can use HasTokenApi trait.

Thank you for replying!

stevebauman commented 3 years ago

The problem is when I call Auth::check() after validating I get false, and the session()->all() is empty. So the problem is that I get passed the validation but the logging in is not stateful or persistence.

Does a session get created inside of your sessions database table upon successful authentication?

As I understand SPAs depend on API tokens and when I use User model from LdapRecord I don't think I can use HasTokenApi trait.

Laravel Jetstream uses cookie based session management, not API tokens, regardless of which stack you use (Livewire or Inertia).

However, it's true that you cannot use an API based authentication driver with plain LDAP authentication, because you cannot store the API token anywhere for the authenticating LDAP user.

Did you change the authentication driver to token inside of your config/auth.php file? It must be session, if so.

If not, please post your config/auth.php file so we can take a closer look.

MuhammedAlkhudiry commented 3 years ago

My company canceled the project so I delete it. However, from what you said, that it's not tokens, I think I know where was the problem.

I may reopen the issue when I get to the same issue with a new project. Thank you for your help! ❤