Skip to content

Commit

Permalink
Merge pull request #7 from JohnGrubba/dev
Browse files Browse the repository at this point in the history
Internal Batch Endpoint
  • Loading branch information
JohnGrubba authored Jul 9, 2024
2 parents 6ac9b72 + 77f2d9e commit a7ca98a
Show file tree
Hide file tree
Showing 16 changed files with 208 additions and 156 deletions.
7 changes: 5 additions & 2 deletions config/configtemplate.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@
"internal_api_key": "CHANGE_ME_NOW",
"internal_columns": [
"_id"
],
"not_updateable_columns": [
"email"
]
},
"account_features": {
"enable_change_password": true,
"change_password_confirm_email": false,
"enable_reset_pswd": true,
"reset_pswd_conf_mail": false,
"2fa": {
"enable": false,
"issuer_name": "EZAuth",
Expand Down
27 changes: 27 additions & 0 deletions docs/advanced/email_templates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
If the provided placeholders are not enough, and you need more logic behind your Templating, you can use our `preprocessing` feature.
This feature allows you to run a custom function on the E-Mail Template before it is sent out. This function will be able to add / modify / remove placeholders from the template. You can also use this function to add custom logic to the template.<br>
Examples of what you can do with this feature:

!!! Info "Usage Examples of Preprocessing E-Mail Templates"
- Adding a Formatted Date to the E-Mail Template
- Utilizing an external Service to generate a QR Code
- Adding a Random Quote to the E-Mail Template
- Sending a Request to an external API

### Example
In this example, we will add a `timestamp` placeholder to the E-Mail Template. This placeholder will contain the current date and time when the E-Mail is sent out.

!!! Note "Preprocessing Function"
- The function should be defined in a Python file in the `config/email` folder. The function should be named `preprocess` and should accept a single parameter `kwargs` which is a dictionary containing all the placeholders available in the E-Mail Template.
- The function should return the modified `kwargs` object.
- The Filename should be the same as the E-Mail Template filename with the `.py` extension. (e.g. `WelcomeMail.py` for the `WelcomeMail.html` template)

In this example, we will add a `timestamp` placeholder to the `ConfirmEmail.html` template.
```python hl_lines="4" linenums="1" title="config/email/ConfirmEmail.py"
from datetime import datetime

def preprocess(kwargs: dict) -> dict:
kwargs["timestamp"] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
return kwargs

```
24 changes: 24 additions & 0 deletions docs/advanced/further_custom.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
If you want to further customize the service you can take a look at the `docker-compose.yml` file in the root directory of the repository. This file contains all the configuration options for the service. You can change the port on which the service is running, the volume mounts, and the environment variables.

#### API Configuration
The Prefix for all Parameters here is `services.api`.
The Following Environment Variables can be set in the `docker-compose.yml` file to configure the API:


| Parameter | Description |
|------------|-------------|
| `ports` | **Datatype:** String <br> **Default:** `"3250:80"` <br> Only change the left (host) side of the ports. The API will always run on Port 80 internally, and can be forwarded to any port on the host system. In this example `3250`. |
| `volumes` | **Datatype:** String <br> **Default:** `"./config:/app/config"` <br> The volume mount for the configuration file. Only change the left (host) side of the configuration folder directory. In this example `./config`. |

#### Database Configuration
The Prefix for all Parameters here is `services.db.environment`.
When changing the database configuration, make sure to also change the `api` section in the `docker-compose.yml` file to reflect the new database connection.
The following environment variables can be set in the `docker-compose.yml` file to configure the database connection:

| Parameter | Description |
|------------|-------------|
| `MONGO_INITDB_ROOT_USERNAME` | **Datatype:** String <br> **Default:** `"admin"` <br> The Root Username for the Database. |
| `MONGO_INITDB_ROOT_PASSWORD` | **Datatype:** String <br> **Default:** `"admin"` <br> The Root Password for the Database. |
| `MONGO_INITDB_DATABASE` | **Datatype:** String <br> **Default:** `"ezauth"` <br> The Database Name. |

You can also change the location of the database data by changing the `volumes` section of the `db` section in the `docker-compose.yml` file.
Original file line number Diff line number Diff line change
@@ -1,58 +1,62 @@
# Configuration

To configure EZAuth you can take a look at the `configtemplate.json` file in the `config` directory. This file contains all the configuration options for EZAuth.

## Parameters table

All configuration parameters are listed in the tables below.
Make sure that all parameters are set correctly before starting the service.

!!! Warning "Apply Configuration"
If you change the configuration file, make sure to restart the service to apply the changes.

### Signup Configuration
| Parameter | Description |
|------------|-------------|
| `signup.enable_conf_email` | **Datatype:** Boolean <br> **Default:** `false` <br> Enable or disable the confirmation E-Mail for new users. |
| `signup.conf_code_expiry` | **Datatype:** Integer <br> **Default:** `5` <br> The time in minutes until the confirmation code expires. |
| `signup.conf_code_complexity` | **Datatype:** Integer <br> **Default:** `1` <br> The complexity of the confirmation code. <br> **Possible Values** <br> <ul><li>**1**: `4 Digit Numeric`</li><li>**2**: `6 Digit Numeric`</li><li>**3**: `4 Characters`</li><li>**4**: `6 Characters`</li></ul> |
| `signup.enable_welcome_email` | **Datatype:** Boolean <br> **Default:** `false` <br> Enable or disable the welcome E-Mail for new users. |


### E-Mail Configuration

!!! Warning "SMTP SSL required"
EZAuth uses SMTP_SSL to send E-Mails. Make sure that your SMTP server supports SSL.
Currently EZAuth does not support STARTTLS.

| Parameter | Description |
|------------|-------------|
| `email.login_usr` | **Datatype:** String <br> **Default:** `""` <br> E-Mail Login Identifier (mostly the E-Mail itself). <br> **Example:** [email protected] |
| `email.login_pwd` | **Datatype:** String <br> **Default:** `""` <br> E-Mail Login Password. |
| `email.sender_email` | **Datatype:** String <br> **Default:** `""` <br> E-Mail address from which the E-Mails are sent (mostly the same as `email.login_usr`) |
| `email.smtp_host` | **Datatype:** String <br> **Default:** `""` <br> SMTP Host for the E-Mail server. <br> **Example:** `smtp.gmail.com` |
| `email.smtp_port` | **Datatype:** Integer <br> **Default:** `465` <br> SMTP Port for the E-Mail server. |

### Session Configuration
| Parameter | Description |
|------------|-------------|
| `session.session_expiry_seconds` | **Datatype:** Integer <br> **Default:** `86400` <br> The time in seconds until a login session expires. Expires on Client (Browser) and on the Server (Database). |
| `session.max_session_count` | **Datatype:** Integer <br> **Default:** `5` <br> Maximum amount of sessions for one User. |
| `session.auto_cookie` | **Datatype:** Boolean <br> **Default:** `true` <br> Specifies if the API should automatically return a `Set-Cookie` header to potentially automatically set the Session Token for the client. May simplify upcoming requests to this API. |
| `session.auto_cookie_name` | **Datatype:** String <br> **Default:** `session` <br> The name of the cookie which will be set by the API. |

### Internal API Configuration

!!! danger "Internal API Key"
Change this **immediately** after cloning the repository. Keeping the default value is a **severe security risk**.

| Parameter | Description |
|------------|-------------|
| `internal.internal_api_key` | **Datatype:** String <br> **Default:** `CHANGE_ME_NOW` <br> This is **sensitive** information and must **never** be exposed anywhere. |
| `internal.internal_columns` | **Datatype:** List <br> **Default:** `["_id"]` <br> Columns that should only be revealed via the internal API. This example will never reveal `_id` to public endpoints, but just to the `/internal` endpoints as well as E-Mails. |

### Account Features Configuration
| Parameter | Description |
|------------|-------------|
| `account_features.enable_change_password` | **Datatype:** Boolean <br> **Default:** `true` <br> Enable or disable the password reset feature. |
| `account_features.change_password_confirm_email` | **Datatype:** Boolean <br> **Default:** `true` <br> Enable or disable the password change confirmation E-Mail. |
# Configuration

To configure EZAuth you can take a look at the `configtemplate.json` file in the `config` directory. This file contains all the configuration options for EZAuth.

## Parameters table

All configuration parameters are listed in the tables below.
Make sure that all parameters are set correctly before starting the service.

!!! Warning "Apply Configuration"
If you change the configuration file, make sure to restart the service to apply the changes.

### Signup Configuration
| Parameter | Description |
|------------|-------------|
| `signup.enable_conf_email` | **Datatype:** Boolean <br> **Default:** `false` <br> Enable or disable the confirmation E-Mail for new users. |
| `signup.conf_code_expiry` | **Datatype:** Integer <br> **Default:** `5` <br> The time in minutes until the confirmation code expires. |
| `signup.conf_code_complexity` | **Datatype:** Integer <br> **Default:** `1` <br> The complexity of the confirmation code. <br> **Possible Values** <br> <ul><li>**1**: `4 Digit Numeric`</li><li>**2**: `6 Digit Numeric`</li><li>**3**: `4 Characters`</li><li>**4**: `6 Characters`</li></ul> |
| `signup.enable_welcome_email` | **Datatype:** Boolean <br> **Default:** `false` <br> Enable or disable the welcome E-Mail for new users. |


### E-Mail Configuration

!!! Warning "SMTP SSL required"
EZAuth uses SMTP_SSL to send E-Mails. Make sure that your SMTP server supports SSL.
Currently EZAuth does not support STARTTLS.

| Parameter | Description |
|------------|-------------|
| `email.login_usr` | **Datatype:** String <br> **Default:** `""` <br> E-Mail Login Identifier (mostly the E-Mail itself). <br> **Example:** [email protected] |
| `email.login_pwd` | **Datatype:** String <br> **Default:** `""` <br> E-Mail Login Password. |
| `email.sender_email` | **Datatype:** String <br> **Default:** `""` <br> E-Mail address from which the E-Mails are sent (mostly the same as `email.login_usr`) |
| `email.smtp_host` | **Datatype:** String <br> **Default:** `""` <br> SMTP Host for the E-Mail server. <br> **Example:** `smtp.gmail.com` |
| `email.smtp_port` | **Datatype:** Integer <br> **Default:** `465` <br> SMTP Port for the E-Mail server. |

### Session Configuration
| Parameter | Description |
|------------|-------------|
| `session.session_expiry_seconds` | **Datatype:** Integer <br> **Default:** `86400` <br> The time in seconds until a login session expires. Expires on Client (Browser) and on the Server (Database). |
| `session.max_session_count` | **Datatype:** Integer <br> **Default:** `5` <br> Maximum amount of sessions for one User. |
| `session.auto_cookie` | **Datatype:** Boolean <br> **Default:** `true` <br> Specifies if the API should automatically return a `Set-Cookie` header to potentially automatically set the Session Token for the client. May simplify upcoming requests to this API. |
| `session.auto_cookie_name` | **Datatype:** String <br> **Default:** `"session"` <br> The name of the cookie which will be set by the API. |

### Internal API Configuration

!!! danger "Internal API Key"
Change this **immediately** after cloning the repository. Keeping the default value is a **severe security risk**.

| Parameter | Description |
|------------|-------------|
| `internal.internal_api_key` | **Datatype:** String <br> **Default:** `"CHANGE_ME_NOW"` <br> This is **sensitive** information and must **never** be exposed anywhere. |
| `internal.internal_columns` | **Datatype:** List <br> **Default:** `["_id"]` <br> Columns that should only be revealed via the internal API. This example will never reveal `_id` to public endpoints, but just to the `/internal` endpoints as well as E-Mails. |
| `internal.not_updateable_columns` | **Datatype:** List <br> **Default:** `["email"]` <br> Columns that should not be able to get updated via the public API. |

### Account Features Configuration
| Parameter | Description |
|------------|-------------|
| `account_features.enable_reset_pswd` | **Datatype:** Boolean <br> **Default:** `true` <br> Enable or disable the password reset feature. |
| `account_features.reset_pswd_conf_mail` | **Datatype:** Boolean <br> **Default:** `true` <br> Enable or disable the password change confirmation E-Mail. |
| `account_features.2fa.enable` | **Datatype:** Boolean <br> **Default:** `false` <br> Enable or disable two factor for Login. 2FA was tested with [Google Authenticator](https://support.google.com/accounts/answer/1066447) and [2FAS Auth](https://2fas.com/) |
| `account_features.2fa.issuer_name` | **Datatype:** String <br> **Default:** `"EZAuth"` <br> How the two factor code will be titled in the users 2FA App. (Mostly the App Name) |
| `account_features.2fa.issuer_image_url` | **Datatype:** String <br> **Default:** `""` <br> URL for an optional Image which will be displayed in the 2FA App. |
Original file line number Diff line number Diff line change
Expand Up @@ -43,33 +43,4 @@ Example: `WelcomeMail` will use the `WelcomeMail.html` template.

!!! Info "Broadcast E-Mails"
By using the Internal API you can send out broadcast e-mails to all users. This can be useful for maintenance notifications or other important information.
You can also provide a custom [MongoDB Filter](https://www.mongodb.com/docs/compass/current/query/filter/) to only send the e-mail to a specific group of users. Example: `{"sexual_preference": "gay"}` -> This will only send the e-mail to users who have `gay` as their `sexual_preference`.

## Advanced E-Mail Templating
If our provided placeholders are not enough, and you need more logic behind your Templating, you can use our `preprocessing` feature.
This feature allows you to run a custom function on the E-Mail Template before it is sent out. This function will be able to add / modify / remove placeholders from the template. You can also use this function to add custom logic to the template.<br>
Examples of what you can do with this feature:

!!! Info "Usage Examples of Preprocessing E-Mail Templates"
- Adding a Formatted Date to the E-Mail Template
- Utilizing an external Service to generate a QR Code
- Adding a Random Quote to the E-Mail Template
- Sending a Request to an external API

### Example
In this example, we will add a `timestamp` placeholder to the E-Mail Template. This placeholder will contain the current date and time when the E-Mail is sent out.

!!! Note "Preprocessing Function"
- The function should be defined in a Python file in the `config/email` folder. The function should be named `preprocess` and should accept a single parameter `kwargs` which is a dictionary containing all the placeholders available in the E-Mail Template.
- The function should return the modified `kwargs` object.
- The Filename should be the same as the E-Mail Template filename with the `.py` extension. (e.g. `WelcomeMail.py` for the `WelcomeMail.html` template)

In this example, we will add a `timestamp` placeholder to the `ConfirmEmail.html` template.
```python hl_lines="4" linenums="1" title="config/email/ConfirmEmail.py"
from datetime import datetime

def preprocess(kwargs: dict) -> dict:
kwargs["timestamp"] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
return kwargs

```
You can also provide a custom [MongoDB Filter](https://www.mongodb.com/docs/compass/current/query/filter/) to only send the e-mail to a specific group of users. Example: `{"sexual_preference": "gay"}` -> This will only send the e-mail to users who have `gay` as their `sexual_preference`.
33 changes: 5 additions & 28 deletions docs/getting-started/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,15 @@ cp config/configtemplate.json config/config.json
```

Then you need to edit the `config/config.json` file to your needs.
For an explanation of the configuration options, see the [Configuration](configuration.md) page.
For an explanation of the configuration options, see the [Configuration](../configuration/configuration.md) page.

### Running the service
!!! Warning "Configure the Service first"
Before you can run the service you need to [configure](../configuration/configuration.md) it.

After you have configured the service you can start it by running the following command:

``` bash
docker compose up -d
```
The service should now be running and you can access the API by navigating to <a href="http://localhost:3250">`http://localhost:3250`</a> in your browser. The API Documentation is available at <a href="http://localhost:3250/docs">`http://localhost:3250/docs`</a>.

### Further Customization
If you want to further customize the service you can take a look at the `docker-compose.yml` file in the root directory of the repository. This file contains all the configuration options for the service. You can change the port on which the service is running, the volume mounts, and the environment variables.

#### API Configuration
The Prefix for all Parameters here is `services.api`.
The Following Environment Variables can be set in the `docker-compose.yml` file to configure the API:


| Parameter | Description |
|------------|-------------|
| `ports` | **Datatype:** String <br> **Default:** `"3250:80"` <br> Only change the left (host) side of the ports. The API will always run on Port 80 internally, and can be forwarded to any port on the host system. In this example `3250`. |
| `volumes` | **Datatype:** String <br> **Default:** `"./config:/app/config"` <br> The volume mount for the configuration file. Only change the left (host) side of the configuration folder directory. In this example `./config`. |

#### Database Configuration
The Prefix for all Parameters here is `services.db.environment`.
When changing the database configuration, make sure to also change the `api` section in the `docker-compose.yml` file to reflect the new database connection.
The following environment variables can be set in the `docker-compose.yml` file to configure the database connection:

| Parameter | Description |
|------------|-------------|
| `MONGO_INITDB_ROOT_USERNAME` | **Datatype:** String <br> **Default:** `"admin"` <br> The Root Username for the Database. |
| `MONGO_INITDB_ROOT_PASSWORD` | **Datatype:** String <br> **Default:** `"admin"` <br> The Root Password for the Database. |
| `MONGO_INITDB_DATABASE` | **Datatype:** String <br> **Default:** `"ezauth"` <br> The Database Name. |

You can also change the location of the database data by changing the `volumes` section of the `db` section in the `docker-compose.yml` file.
The service should now be running and you can access the API by navigating to <a href="http://localhost:3250">`http://localhost:3250`</a> in your browser. The API Documentation is available at <a href="http://localhost:3250/docs">`http://localhost:3250/docs`</a>.
Loading

0 comments on commit a7ca98a

Please sign in to comment.