Authentication using cookie without users table

Published 6 days ago by [email protected]

Hello, I have what seems to be a simple requirement for authenticating with my laravel 5.5 app. In our intranet, users authenticate through a company-site, which when successfully authenticated, it sets an encrypted browser cookie with the user's ID, name, and additional items. Finally, it redirects the user back to the page that called it.

On my end, the cookie then gets decrypted through PHP. Once here, my app should authenticate using the decrypted user ID, saving the name and other info provided under Auth::User. However, I don't want to have a database with over 500k entries to look up the user, I just want any employee to be able to log in. So I believe what I want is Auth::User to use GenericUser where I set the user based on the decrypted cookie info. I've tried following instructions from the following pages:

But I can't get it to work. I can't figure out the proper way to create a custom authentication provider nor how to create a custom user provider.

I have a site which doesn't use Laravel and the way I authenticate is checking for the cookie to be set and not expired, then setting session variables such as REMOTE_USER.

If anyone has any ideas, I'm open to try them. I'm still a beginner with Laravel, so I may ask additional questions.

Thanks in advance

5 days ago (770,895 XP)

Create a user on the fly using the User model (User::firstOrCreate([])) and then log them in with Auth::login

You can use all the usual Auth functionality, the only downside is creating new users as and when they login so your users table will grow over time. This is not a bad thing if users need to store any personal settings, plus you can see who is using the app

5 days ago (64,100 XP)

We use Shibboleth IAM for company wide authentication. After shib auth, users are returned to the laravel app with various server variables set.. I then follow the process as outlined by @Snapey to use Laravel auth semantics... Yes, you will have 1 user row per employee who accesses your site... I don't think you can avoid this (and honestly, it falls in the bucket of items which does not warrant any action).

Please sign in or create an account to participate in this conversation.