Skip to content

Commit 807b4fc

Browse files
author
ahmadhuss
committed
docs: Update README.md
1 parent 8787195 commit 807b4fc

File tree

1 file changed

+136
-67
lines changed

1 file changed

+136
-67
lines changed

README.md

Lines changed: 136 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
# How can we use this repo?
22

3+
- [Installation](#install)
4+
- [Multi Authentication](#multi-authentication)
35

46
# Install
5-
```sh
6-
composer install
7-
```
7+
```sh
8+
composer install
9+
```
810
Next you can clone the `.env.example` file into the `.env` file. This means that you have to create the same file in the `root` directory under a different name e.g. `.env` and copy paste the same credentials like `.env.example` file.
911

1012
Laravel has a built-in CLI tool called `artisan`. Your application must generate a unique base 64 key that Laravel uses behind the scenes to bootstrap this project.
1113

1214
**Command:**
1315

14-
```sh
15-
php artisan key:generate
16-
```
16+
```sh
17+
php artisan key:generate
18+
```
1719

1820
It will automatically find your `.env` file and place the base 64 value in the file.
1921

2022
**Output inside the file:**
21-
```
22-
APP_KEY=base64:T0huMR5Wx9EoDmjTxniKTofHD/7cOiDeVVD9eTKuCa0=
23-
```
23+
```
24+
APP_KEY=base64:T0huMR5Wx9EoDmjTxniKTofHD/7cOiDeVVD9eTKuCa0=
25+
```
2426

2527
## Additional Note:
2628
As you can see it is necessary to create the `.env` file in your local to bootstrap the project. But `Laravel` contains 2 methods to connect to the database server.
@@ -33,89 +35,156 @@ As you can see it is necessary to create the `.env` file in your local to bootst
3335
## Use of the `.env` variables:
3436

3537
When you create this file with copy paste credentials you can see default; the database variables are written something like this:
36-
```
37-
DB_CONNECTION=mysql
38-
DB_HOST=127.0.0.1
39-
DB_PORT=3306
40-
DB_DATABASE=test_app
41-
DB_USERNAME=root
42-
DB_PASSWORD=
43-
```
38+
```
39+
DB_CONNECTION=mysql
40+
DB_HOST=127.0.0.1
41+
DB_PORT=3306
42+
DB_DATABASE=ui_multiauth
43+
DB_USERNAME=root
44+
DB_PASSWORD=
45+
```
4446

4547
You can edit values according to your own database personal preference. I am using Postgres in this case.
4648

47-
## Use of the file located at the `config/database.php`
49+
## Use of the file located at the `config/database.php`
4850

4951
**Note:** When Laravel bootstraps the project it gives priority to the `.env` file as compared to `config/**` files. You can see `config/database.php` file contains an associated array with default database settings like this.
5052

51-
```
52-
return [
53-
54-
'default' => env('DB_CONNECTION', 'mysql'),
55-
'connections' => [
56-
'mysql' => [
57-
'driver' => 'mysql',
58-
'url' => env('DATABASE_URL'),
59-
'host' => env('DB_HOST', '127.0.0.1'),
60-
'port' => env('DB_PORT', '3306'),
61-
'database' => env('DB_DATABASE', 'forge'),
62-
'username' => env('DB_USERNAME', 'forge'),
63-
'password' => env('DB_PASSWORD', ''),
64-
'unix_socket' => env('DB_SOCKET', ''),
65-
'charset' => 'utf8mb4',
66-
'collation' => 'utf8mb4_unicode_ci',
67-
'prefix' => '',
68-
'prefix_indexes' => true,
69-
'strict' => true,
70-
'engine' => null,
71-
'options' => extension_loaded('pdo_mysql') ? array_filter([
72-
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
73-
]) : [],
74-
],
75-
]
76-
]
77-
```
53+
```
54+
return [
55+
56+
'default' => env('DB_CONNECTION', 'mysql'),
57+
'connections' => [
58+
'mysql' => [
59+
'driver' => 'mysql',
60+
'url' => env('DATABASE_URL'),
61+
'host' => env('DB_HOST', '127.0.0.1'),
62+
'port' => env('DB_PORT', '3306'),
63+
'database' => env('DB_DATABASE', 'forge'),
64+
'username' => env('DB_USERNAME', 'forge'),
65+
'password' => env('DB_PASSWORD', ''),
66+
'unix_socket' => env('DB_SOCKET', ''),
67+
'charset' => 'utf8mb4',
68+
'collation' => 'utf8mb4_unicode_ci',
69+
'prefix' => '',
70+
'prefix_indexes' => true,
71+
'strict' => true,
72+
'engine' => null,
73+
'options' => extension_loaded('pdo_mysql') ? array_filter([
74+
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
75+
]) : [],
76+
],
77+
]
78+
]
79+
```
7880

7981
You can only use these settings if variables from the `.env` file will be deleted. Otherwise, Laravel gives priority to `.env` variables.
8082

8183
Delete the variables from the `.env`:
8284

8385

84-
~~DB_CONNECTION=mysql~~
85-
~~DB_HOST=127.0.0.1~~
86-
~~DB_PORT=3306~~
87-
~~DB_DATABASE=test_app~~
88-
~~DB_USERNAME=root~~
86+
~~DB_CONNECTION=mysql~~
87+
~~DB_HOST=127.0.0.1~~
88+
~~DB_PORT=3306~~
89+
~~DB_DATABASE=test_app~~
90+
~~DB_USERNAME=root~~
8991
~~DB_PASSWORD=~~
9092

9193
Lastly, Update the `config/database.php` with your database server settings:
9294

93-
```
94-
'default' => env('DB_CONNECTION', 'pgsql')
95-
'database' => env('DB_DATABASE', 'ui_multiauth'),
96-
'username' => env('DB_USERNAME', 'postgres'),
97-
'password' => env('DB_PASSWORD', 'a')
98-
```
95+
```
96+
'default' => env('DB_CONNECTION', 'pgsql')
97+
'database' => env('DB_DATABASE', 'ui_multiauth'),
98+
'username' => env('DB_USERNAME', 'postgres'),
99+
'password' => env('DB_PASSWORD', 'a')
100+
```
99101

100102
# Database
101103
I am using **Postgres** and inside `.env` file my database server credentials are:
102-
```
103-
DB_CONNECTION=pgsql
104-
DB_HOST=127.0.0.1
105-
DB_PORT=5432
106-
DB_DATABASE=invoicer_test
107-
DB_USERNAME=postgres
108-
DB_PASSWORD=a
109-
```
104+
```
105+
DB_CONNECTION=pgsql
106+
DB_HOST=127.0.0.1
107+
DB_PORT=5432
108+
DB_DATABASE=invoicer_test
109+
DB_USERNAME=postgres
110+
DB_PASSWORD=a
111+
```
110112

111113
However, your main server and database server get started.
112114

113115
# Migration (Transform into real database tables)
114116
At the last make sure after updating your database settings. Please use `artisan` CLI to migrate the database tables.
115-
```sh
116-
php artisan migrate
117-
```
117+
```sh
118+
php artisan migrate
119+
```
118120

121+
# Multi-Authentication
122+
This information is not about the authentication of APIs, but rather about the authentication we see in the creation of web applications.
123+
124+
In general, there are 3 types of authentications when we create web applications. If you know any other please tell me.
125+
126+
127+
- [Simple authentication](#simple-authentication)
128+
- [Multi authentication](#multi-authentication)
129+
- [Role-based authentication](#role-based-authentication)
130+
131+
### Simple authentication
132+
It only uses one type of `people` and `1 table`. The website owner manually edits the database from the database server.
133+
134+
### Multi authentication
135+
136+
We store records in more than one table. So we authenticate them based on their credentials which will be stored in the database.
137+
138+
### Example:
139+
**School management**:
140+
We create authentication for different type of people for example: `Admins`, `Teachers`, `Moderators`, `Parents` & `Students`.
141+
142+
In this, we have to create multiple authentications for these types of people and each people represents a separate database table inside the database.
143+
144+
*What if we depend upon only a single table named `users` for all these people authentication?*
145+
146+
The table will be bloated and many records will reside on the same table and difficult to differentiate the user. So it is best practice to create separate table for each type of people.
147+
148+
The table will be bloated and many records will reside on the same table and difficult to differentiate the user. So it is best practice to create a separate table for each type of person.
149+
150+
- admins
151+
- moderators
152+
- students
153+
- parents
154+
- teachers
155+
156+
In a multi-authentication system, we can log in to different types of people at the same time. for example, `admin` and `student` can log in at the same time, and if you log out (destroy the session) from the admin account then it will not affect the `student` login session.
157+
158+
### Example 2:
159+
160+
At e-commerce website, we deal with 3 kinds of people.
161+
`users`, `sellers` & `admins`.
162+
163+
### Role based Authentication
164+
165+
We usually see this kind of authentication on blogging websites. As there is only one owner of the website who creates different users and assigns them a role to manipulate the content of the website.
166+
167+
In this system we create 2 tables that has parent child relationship.
168+
`roles` & `users` (In this table we create a column called `role_id` which is a foreign key and refers to the `roles` table column.)
169+
170+
In role-based authentication, the administrator has to create permissions to separate different permissions by role.
171+
172+
**Note:**
173+
This repo is using a package named [laravel-ui](https://github.com/laravel/ui) and using a second authentication method and creating 2 tables `admins` & `users`.
174+
175+
The security of Laravel authentication depends on 2 things; `Guards`(Protectors) and `Providers`.
176+
177+
** Guard: **
178+
The Guard explains how the user is authentic to each request. By default Laravel ships with `session` guard.
179+
180+
**What is session?**
181+
182+
*Whenever clients visit our website, our PHP server will generate a cookie with `session_ID` and some content inside the client browser and most importantly a `session` file will also be created in our server. It contains the same `session_ID` and content.
183+
184+
*Now when the user goes back to the website, the server will check and match Does the server's `session-ID` match the browser cookie? If so, the user is authentic.*
185+
186+
** Provider: **
187+
What kind of permanent storage mechanism do you want to use to retrieve users? Do you want to use `eloquent` or `query builder`?
119188

120189
# Deployment
121190
[Heroku](https://www.heroku.com)

0 commit comments

Comments
 (0)