Skip to content

Commit 9d6558a

Browse files
authored
Merge pull request #10 from CodeShellDev/dev
v1.1.0
2 parents 55ff9dd + 1b9f29b commit 9d6558a

26 files changed

Lines changed: 2421 additions & 2294 deletions

‎.dockerignore‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
.git
33
.github
44
.env
5+
examples
6+
screenshots
57
docker-compose.yaml
6-
LICENSE
78
*.md
89
node_modules
9-
*.pem
10+
*.pem
11+
Dockerfile
Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,84 @@
11
# Mailauth
22

3-
Mailauth is a Mailbox Manager which enables you too select between your Mailboxes and authenticate with your Mailserver (like [mailcow](https://github.com/mailcow/mailcow-dockerized))
3+
Mailauth is a mailbox manager that allows users to select between multiple mailboxes and authenticate with their mail server (such as [mailcow](https://github.com/mailcow/mailcow-dockerized)) through an OAuth2-compatible identity provider.
44

55
## Screenshots
66

7-
![mailauth-home](https://github.com/user-attachments/assets/934fb3a3-3160-4fcb-a30e-10b62a804411)
7+
**Home**
8+
![mailauth home](./screenshots/home.png)
9+
10+
**Select flow**
11+
![mailauth select flow](./screenshots/select-flow.png)
812

913
## Getting Started
1014

11-
Get the latest version of the `docker-compose.yaml` file:
15+
### Docker Compose
16+
17+
Download the latest version of the `docker-compose.yaml` file:
1218

1319
```yaml
14-
{{{ #://docker-compose.yaml }}}
20+
+{{{ read "docker-compose.yaml" }}}
1521
```
1622

17-
### Setup
23+
### Configuration
1824

19-
Mailauth _currently_ works by modifying the `email` claim during Token Exchange and Userinfo,
20-
this means that you **will have to** use a IdP (like [authentik](https://goauthentik.io)).
25+
Mailauth currently works by modifying the `email` claim during OAuth2 **Token Exchange** and **UserInfo** requests.
2126

22-
Create a `.env` file inside of you `docker-compose.yaml` directory and copy the template below
27+
Because of this, Mailauth requires an external Identity Provider (IdP), such as [authentik](https://goauthentik.io).
28+
29+
Create a `.env` file in the same directory as your `docker-compose.yaml` and copy the configuration template:
2330

2431
```dotenv
25-
{{{ #://examples/config.env }}}
32+
+{{{ read "examples/config.env" }}}
2633
```
2734

28-
Now you need to setup a Oauth Authentication Method in your mailserver,
29-
but instead of using your IdP's endpoints you use:
35+
### OAuth Setup
3036

31-
* `/oauth/mail/authorize`
32-
* `/oauth/mail/token`
33-
* `/oauth/mail/userinfo`
37+
Configure an OAuth authentication method in your mail server.
3438

35-
And set Redirect URI to the one from your `.env` file.
39+
Instead of using your IdP's OAuth endpoints, use the Mailauth endpoints:
3640

37-
Next create `init-mongo.js` in your working directory:
41+
| Endpoint | URL |
42+
| -------------- | ----------------------- |
43+
| Authorization | `/oauth/mail/authorize` |
44+
| Token Exchange | `/oauth/mail/token` |
45+
| User Info | `/oauth/mail/userinfo` |
3846

39-
```js
40-
{{{ #://examples/init-mongo.js }}}
41-
```
47+
Set the redirect URI to the value configured in your `.env` file.
4248

43-
### Reverse Proxy
49+
## Reverse Proxy
4450

45-
When working with OAuth2 and Auth in general it is recommended to be sure to use secure connections,
46-
here you will see a Reverse Proxy implementation with traefik:
51+
OAuth2 authentication should always be used over a secure connection.
52+
53+
The following example shows a reverse proxy setup using Traefik:
4754

4855
```yaml
49-
{{{ #://examples/traefik.docker-compose.yaml }}}
56+
+{{{ read "examples/traefik.docker-compose.yaml" }}}
5057
```
5158

5259
## Usage
5360

54-
When authenticating via mailauth you get redirected to your actual IdP then to `/select`,
55-
where you will be able to select your mailbox, mailauth changes the `email` claim and now you're logged in.
61+
When authenticating through Mailauth:
62+
63+
1. You are redirected to your configured IdP.
64+
2. After successful authentication, Mailauth redirects you to the mailbox selection page.
65+
3. You select the mailbox you want to authenticate with.
66+
4. Mailauth updates the `email` claim and completes the OAuth2 flow.
67+
68+
You are now authenticated with the selected mailbox.
5669

5770
## Contributing
5871

59-
Found an Issue or want to see something implemented into Mailauth?
60-
Open up an Issue or start a Pull Request!
72+
Found a bug or have an idea for improving Mailauth?
73+
74+
Feel free to open an issue or submit a pull request.
6175

62-
But always be respectful and patient, we are all volunteers after all.
76+
Please be respectful and patient when contributing. Mailauth is maintained by volunteers.
6377

6478
## Supporting
6579

66-
Found this Project useful? Let others know about Mailauth by ⭐️ this Repo!
80+
If you find Mailauth useful, consider giving the repository a ⭐ to help others discover it.
6781

6882
## License
6983

70-
[MIT](https://choosealicense.com/licenses/mit/)
84+
This Project is licensed under the [MIT License](./LICENSE).

‎.github/workflows/docker-image-dev.yml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ on:
55
branches:
66
- dev
77
paths-ignore:
8-
- ".**"
8+
- .**
9+
- examples/**
910

1011
jobs:
1112
update:

‎.github/workflows/readme-update.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
- main
77
paths:
88
- docker-compose.yaml
9+
- examples/**
910
- .github/templates/README.template.md
1011

1112
jobs:

‎Dockerfile‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
FROM node:latest
1+
FROM node:alpine
22

33
WORKDIR /app
44

55
ENV NODE_ENV=production
6-
ENV PORT=80
6+
ENV PORT=8070
7+
8+
COPY package*.json ./
9+
10+
RUN npm ci --omit=dev && npm cache clean --force
711

812
COPY . .
913

10-
RUN npm install
14+
RUN mkdir -p /app/data/secrets && chown -R node:node /app
15+
16+
USER node
1117

12-
EXPOSE 80
18+
EXPOSE 8070
1319

14-
CMD ["npm", "start", "-s"]
20+
CMD ["node", "src/server.js"]

‎docker-compose.yaml‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
1-
---
21
services:
32
mailauth:
43
image: ghcr.io/codeshelldev/mailauth:latest
54
container_name: mailauth
65
ports:
7-
- "80:80"
6+
- "8070:8070"
7+
environment:
8+
DB_HOST: ${DB_HOST:-mongo:27017}
9+
DB_USER: ${DB_USER:-admin}
10+
DB_NAME: ${DB_NAME:-mailauth}
11+
REDIS_HOST: ${REDIS_HOST:-redis:6379}
812
env_file:
913
- .env
14+
depends_on:
15+
- mongo
16+
- redis
1017
restart: unless-stopped
1118
networks:
12-
mailauth:
13-
aliases:
14-
- mailauth
19+
- mailauth
1520

16-
mongodb:
17-
image: mongo:latest # Use arm64v8/mongo for ARM Architecture
21+
mongo:
22+
image: mongo:7
1823
container_name: mailauth-db
24+
environment:
25+
MONGO_INITDB_ROOT_USERNAME: ${DB_USER:-admin}
26+
MONGO_INITDB_ROOT_PASSWORD: ${DB_PASSWORD}
27+
MONGO_INITDB_DATABASE: ${DB_NAME:-mailauth}
1928
volumes:
2029
- db:/data/db
21-
- ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js
22-
env_file:
23-
- .env
2430
networks:
25-
mailauth:
26-
aliases:
27-
- mongo
31+
- mailauth
2832
restart: unless-stopped
2933

3034
redis:
31-
image: redis:latest
35+
image: redis:7-alpine
3236
container_name: mailauth-redis
3337
command: ["redis-server", "--requirepass", "${REDIS_PASSWORD}"]
34-
env_file:
35-
- .env
3638
networks:
37-
mailauth:
38-
aliases:
39-
- redis
39+
- mailauth
4040
restart: unless-stopped
4141

4242
networks:

‎examples/config.env‎

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,13 @@ APP_TOKEN_ENDPOINT=
2323
APP_USERINFO_ENDPOINT=
2424
APP_LOGOUT_ENDPOINT=
2525

26-
APP_REDIRECT_PATH=/oauth/app/callback
27-
28-
# DB
29-
30-
MONGO_INITDB_ROOT_USERNAME=admin
31-
MONGO_INITDB_ROOT_PASSWORD=SECURE_ROOT_PW
32-
MONGO_INITDB_DATABASE=mailauth
33-
34-
MONGO_USER=mailauth
35-
MONGO_PW=SECURE_PW
36-
37-
# ---- #
26+
# Storage
3827

28+
DB_PASSWORD=SECURE_ROOT_PW
3929
REDIS_PASSWORD=SECURE_REDIS_PW
4030

4131
# General
4232

4333
SESSION_SECRET=SECURE_KEY # Gen with openssl
4434

45-
HOST=https://mailauth.domain.com
46-
47-
PREFIX=/ # Optional
48-
49-
DB_HOST=mongodb://${MONGO_USER}:${MONGO_PW}@mongo:27017/${MONGO_INITDB_DATABASE}
50-
REDIS_HOST=redis://default:${REDIS_PASSWORD}@redis:6379
35+
HOST=https://mailauth.domain.com

‎examples/defaults.env‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
DB_USER=admin
2+
DB_NAME=mailauth
3+
4+
DB_HOST=mongo:27017
5+
REDIS_HOST=redis:6379
6+
7+
APP_REDIRECT_PATH=/oauth/app/callback
8+
9+
PREFIX=/

‎examples/init-mongo.js‎

Lines changed: 0 additions & 12 deletions
This file was deleted.

‎examples/traefik.docker-compose.yaml‎

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,44 @@ services:
1010
- traefik.http.routers.mailauth-secure.tls=true
1111
- traefik.http.routers.mailauth-secure.tls.certresolver=resolver
1212
- traefik.http.routers.mailauth-secure.service=mailauth-svc
13-
- traefik.http.services.mailauth-svc.loadbalancer.server.port=80
13+
- traefik.http.services.mailauth-svc.loadbalancer.server.port=8070
1414
- traefik.docker.network=proxy
15+
environment:
16+
DB_HOST: ${DB_HOST:-mongo:27017}
17+
DB_USER: ${DB_USER:-admin}
18+
DB_NAME: ${DB_NAME:-mailauth}
19+
REDIS_HOST: ${REDIS_HOST:-redis:6379}
1520
env_file:
1621
- .env
22+
depends_on:
23+
- mongo
24+
- redis
1725
restart: unless-stopped
1826
networks:
1927
mailauth:
2028
aliases:
2129
- mailauth
2230
proxy:
2331

24-
mongodb:
25-
image: mongo:latest # Use arm64v8/mongo for ARM Architecture
32+
mongo:
33+
image: mongo:7
2634
container_name: mailauth-db
35+
environment:
36+
MONGO_INITDB_ROOT_USERNAME: ${DB_USER:-admin}
37+
MONGO_INITDB_ROOT_PASSWORD: ${DB_PASSWORD}
38+
MONGO_INITDB_DATABASE: ${DB_NAME:-mailauth}
2739
volumes:
2840
- db:/data/db
29-
- ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js
30-
env_file:
31-
- .env
3241
networks:
33-
mailauth:
34-
aliases:
35-
- mongo
42+
- mailauth
3643
restart: unless-stopped
3744

3845
redis:
39-
image: redis:latest
46+
image: redis:7-alpine
4047
container_name: mailauth-redis
4148
command: ["redis-server", "--requirepass", "${REDIS_PASSWORD}"]
42-
env_file:
43-
- .env
4449
networks:
45-
mailauth:
46-
aliases:
47-
- redis
50+
- mailauth
4851
restart: unless-stopped
4952

5053
networks:

0 commit comments

Comments
 (0)