I want to use MariaDB (mysql) users to authenticate in a Laravel app. So instead of having a users table and a single database user for the whole application I want each login to be a separate database user and have permissions managed by the database.
This will be an internal app used by no more than 10 users.
Do I need to create a custom user provider in Laravel? What would be the best way to go about this?
Related
I want to create a new Laravel 5.8 based application using the database of an old PHP based application.
The problem is: My previous project uses five tables to store user-related information and all of those tables are used during login (to set session data).
Those tables are user_account, user_role, user_partner_portal, user_access_control, and user_control_access_right.
The relationship between those tables are in the below images:
By default, laravel uses users table to handle authentication and I don't know how to customize Laravel login system so that I can use all of those five tables during login to authenticate a user and also store the user-related information into the session.
I am primarily using CodeIgniter for all of my projects and it is very easy to do that authentication using CodeIgniter. But I am new in Laravel, so I can't figure it out.
So my question is: Is it possible using laravel to design such an authentication system? If yes then how?
TIA
So laravel uses LoginController class for the login. Inside there you are going to find the function authenticate.
Laravel put's the predefined logic there but if you want to make it really custom like update all your tables etc etc you are free to do it.
You can even create your own class and change the login route to point to your own controller. Basically you can do anything you like.
Hi I have model table where i have mentioned the user role ID.
What i want to know is
when the user login i want to check the user data with the model
table and i want get the user role ID.
after getting the role id i want to bind or assign the particular database to the user based on the user role's ID.
Each client want to be assigned with individual database.
What i have
I have more than one client and a single client will have 10 to 20
user
I have a Native mobile application on front end and i use PHP on
backend.
Till now i used one database per app so i have no idea about dynamically assigning database to individual client/user.
In my case
I am planing to rent AWS, or Microsoft Azure where i want to assign individual database to individual clients.
Client - is an organization.
User- are people who use my application within thin the organization.
Thanks in advance....
If I understand it correctly you just need only open a new database link connection with the database of the user's company.
If all the databases are on the same host machine then it is trivial depending on what PHP library you are using. For example with MySQLi:
Same Host:
$databaseLink->select_db("company_of_the_user_db_name");
Other host:
$databaseLink->close();
$databaseLink = new mysqli("newhost", "newUser", "newPass");
$databaseLink->select_db("company_of_the_user_db_name");
Where $databaseLink is your old db link where the users table is stored.
Almost all PHP Database libraries have a function like select_db, otherwise you can close the connection and open a new one.
I'm trying to build a Multi tenant SaaS application, and i know there are multiple approaches to that, but i picked the multi-database one i think it would fit most.
so I create a db for each tenant and store a table of tenants in the main db
and connect users to their respective db based on the subdomain.
now my issue here is where to store the users, in the main db? or the tenant db, storing the users in the main db is going to make it difficult to get user related models in other db's, but storing it inside tenants db would make it difficult to authenticate on all users ...
also what's the best scenario?
authenticate, get jwt token.
send token with each request.
on each request validate token, check subdomain, connect to respective tenant db, execute request.
is this a good approach? what should I do with the users table issue?
ThnQ
I can offer third option. Have user both in tenant and main db. You can then create procedure to update main db when user changes in tenant db (or vice versa).
Also, I don't know models in Laravel, but MySQL doesn't have problem with cross database JOINs.
Good option will be to keep users in tenant database. As you are distinguishing your tenant based on sub-domain, you can tell your authentication system to query sub-domain specific database.
Sharing flow of authentication
User hits the sub-domain to login for application
User credentials will be sent to application
Before passing credentials to authentication, decide database for user authentication based on sub-domain from which user came.
Pass database name, user credentials to authentication system
Authentication system query specific database and authenticate user
Generate session
I have a web app which I need to duplicate for multiple clients.
Each client will have his own server space and a database.
Each database will have one user table per client and they have independent data from each others.
Clients could access to their site via sub-domain URLs.
One client's URL may look like this ex: www.abcgroup.example.com (client: abcgroup)
I want to have one centralized login page at www.example.com/login.
Once a client login, he will be redirected to abcgroup.example.com automatically, without having to type his own sub-domain URL.
ex:This site managed to do it https://tictail.com/
Problem is that I have multiple databases with multiple user tables. So how can I authenticate users globally from one login page?
I'm not sure whether I have to check against all the user tables in client databases.
Do I need to read from all the user tables? (I'm using Codeigniter 2)
Thanks!
2 ways to do this:
Have a central DB that has all the users. This makes sure all the users are unique. Having multiple DBs, you may run into duplicate users.
Making the user select or type in the subdomain in the login page. Some web apps do this.
I have implement SOS concept between two php application. it application it available different domain like one is www.example.com and another is www.test.com.
My required following condition.
1.When user is login any appplication to login this user with check user name and password into mysql database table
2.After login any application username and password is not required/reenter user can directly login this application similar to Google.
3.When user logout at time both application can be logout.
-->my first application can be created Yii framework and another is moodle
please give idea to implement this concept in my both application