baopham / laravel-dynamodb

Eloquent syntax for DynamoDB
https://packagist.org/packages/baopham/dynamodb
MIT License
484 stars 127 forks source link

Multi Auth system in laravel #153

Open koushikSen opened 5 years ago

koushikSen commented 5 years ago

I am doing a project where multi-auth is necessary. Does this package support laravel multi-auth? even though I set up project environment as multi auth suggests, DynamDB package always getting the content of user model.

baopham commented 5 years ago

Sorry, could you give more clarification on your use case? What was the setup (Laravel and DynamoDB)? What is the expectation of using this library? What do you want to achieve?

koushikSen commented 5 years ago

Hi @baopham, sorry for the late reply. It is in laravel 5.4 and with dynamodb 0.5.0, I wanted to use the "Users" table for user panel login and separate "Admins" table for managing. I wanted to use DynamoDBUsers model for Users and a custom DynamoDBAdmin model for Admins and both will use Auth or login validation. Now even if I set Auth:: guard('admin') it is searching Users table for that particular login credential.

is it clear from the above definition what I am trying to achieve?

baopham commented 5 years ago

This library doesn't work with Laravel auth out of the box. Usually when you want "users", you would want "roles" too and that involves setting up relationship like many-to-many and DynamoDB doesn't play well with that.

But seems like there is a need for it as you're not the first person asking about auth. Please refer to #157 for progress (if I happen to get enough time to work on it).

zoul0813 commented 5 years ago

If using DynamoDB, I’d recommend Cognito as an auth backend.

My app does client side auth, and passes an auth token cookie to the server - whenever I need to check if the user is logged in, that token goes through my custom Cognito auth middleware which verifies the jwtToken. IF my backend needs access to the User record itself, then I pull it out of Cognito/DynamoDB depending on what I’m doing (Cognito syncs profile data with Dynamo, but not the other way around).

It results in very few reads from Dynamo, and does not require my backend to cache the user either... as I usually don’t need to know anything other than “are they logged in” or “are they a member of X group”.

Vue is used to render any user specific data on the front end - such as username in the user dropdown of the menu, etc.

foo123 commented 4 years ago

I am also interetsed in multi-auth integration. @zoul0813 can you explain a little more about your cognito middleware in laravel? Are you using this package https://github.com/black-bits/laravel-cognito-auth?

zoul0813 commented 4 years ago

@foo123, no. I use the cognito client side JavaScript to authenticate and simply pass the auth token that Cognito generates as a cookie.

The middleware was custom written, and just decided the jwt auth token and verified it. If it was valid, then the user was authenticated.

I had it setup to sync Cognito user data with a lambda function, which wrote the data to dynamodb.

My profile edit was also client side, and would write data to Cognito... which would then trigger the lambda sync.

Unfortunately, I can’t provide any code or examples as I’m not longer working on that project and do not have access to it.

foo123 commented 4 years ago

@zoul0813 that is fair enough explanation. Got it. Thanks!