Skip to content

Commit 2df88d3

Browse files
refactor: overhaul server and upgrade AuthC to v5 (#26)
* feat(api): add integrated OAS specification at /docs/api endpoint and improve documentation. * refactor(server): restructure/simplify API routes and frontend forms for maintainability and readability * chore(deps): upgrade AuthC dependencies and server to version 5
1 parent fdcada3 commit 2df88d3

File tree

122 files changed

+10941
-8402
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+10941
-8402
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ node_modules
66
serverkey
77
adminkey
88
.DS_Store
9-
.idea
9+
.idea
10+
/client/dist

.vscode/extensions.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
// List of extensions which should be recommended for users of this workspace.
66
"recommendations": [
7-
"humao.rest-client"
87
],
98
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
109
"unwantedRecommendations": [

Dockerfile

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,51 @@
1-
FROM node:18-slim as builder
1+
# Stage 1: Builder stage (full build environment)
2+
FROM node:22-slim AS builder
23

34
LABEL org.opencontainers.image.title="AuthCompanion"
4-
LABEL org.opencontainers.image.version="4.0.0-beta.1"
5-
LABEL org.opencontainers.image.description="An admin-friendly, User Management Server (with Passkeys & JWTs) - for seamless and secure integration of user authentication"
5+
LABEL org.opencontainers.image.version="5.0.0-beta.1"
6+
LABEL org.opencontainers.image.description="An admin-friendly, User Management Server (with Passkeys & JWTs)"
67
LABEL org.opencontainers.image.authors="Paul Fischer"
78
LABEL org.opencontainers.image.source=https://github.com/authcompanion/authcompanion2
89

9-
# update packages, to reduce risk of vulnerabilities
10-
RUN apt-get update && apt-get upgrade -y && apt-get autoclean -y && apt-get autoremove -y
10+
WORKDIR /app
1111

12-
# set a non privileged user to use when running this image
13-
RUN groupadd -r nodejs && useradd -g nodejs -s /bin/bash -d /home/nodejs -m nodejs
14-
USER nodejs
15-
# set right (secure) folder permissions
16-
RUN mkdir -p /home/nodejs/app/node_modules /home/nodejs/app/authdata && chown -R nodejs:nodejs /home/nodejs/app
12+
# Copy package files first for caching
13+
COPY package*.json ./
14+
# Install all dependencies including devDependencies
15+
RUN npm install --include=dev
16+
# Copy all project files
17+
COPY . .
18+
# Build the application
19+
RUN npm run build
1720

18-
WORKDIR /home/nodejs/app
21+
# Stage 2: Production stage (lean image)
22+
FROM node:22-slim
1923

20-
# set default node env
21-
ARG NODE_ENV=production
22-
# ARG NODE_ENV=production
23-
# to be able to run tests (for example in CI), do not set production as environment
24-
ENV NODE_ENV=${NODE_ENV}
24+
# Create non-root user and set directory permissions
25+
RUN groupadd -r nodejs && \
26+
useradd -g nodejs -s /bin/bash -d /home/nodejs -m nodejs && \
27+
mkdir -p /home/nodejs/app && \
28+
chown -R nodejs:nodejs /home/nodejs/app
2529

26-
ENV NPM_CONFIG_LOGLEVEL=warn
30+
RUN mkdir -p /data && \
31+
chown nodejs:nodejs /data && \
32+
chmod 755 /data
2733

28-
# copy project definition/dependencies files, for better reuse of layers
29-
COPY --chown=nodejs:nodejs package*.json ./
34+
WORKDIR /home/nodejs/app
3035

31-
# install dependencies here, for better reuse of layers
32-
RUN npm install
36+
# Copy application files with correct ownership
37+
COPY --from=builder --chown=nodejs:nodejs /app .
3338

34-
# copy all sources in the container (exclusions in .dockerignore file)
35-
COPY --chown=nodejs:nodejs . .
39+
# Set environment variables directly in Dockerfile
40+
ENV NODE_ENV=production
41+
ENV NPM_CONFIG_LOGLEVEL=warn
3642

37-
# build/pack binaries from sources
43+
# Final cleanup
44+
RUN npm prune --omit=dev && \
45+
npm cache clean --force
3846

39-
# This results in a single layer image
40-
# FROM node:lts-alpine AS release
41-
# COPY --from=builder /dist /dist
47+
USER nodejs
4248

43-
# exposed port/s
4449
EXPOSE 3002
4550

46-
# add an healthcheck, useful
47-
# healthcheck with curl, but not recommended
48-
# HEALTHCHECK CMD curl --fail http://localhost:8000/health || exit 1
49-
# healthcheck by calling the additional script exposed by the plugin
50-
# HEALTHCHECK --interval=30s --timeout=10s --start-period=5s CMD npm run healthcheck-manual
51-
52-
# ENTRYPOINT [ "node" ]
53-
# CMD [ "npm", "start" ]
54-
CMD [ "node", "server.js" ]
55-
56-
# end.
51+
CMD [ "node", "server.js" ]

Dockerfile.arm64

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,43 @@
1-
# Stage 1: Build the application
2-
FROM node:18-slim as builder
1+
# Stage 1: Builder stage
2+
FROM --platform=linux/arm64 node:22-slim AS builder
33

44
LABEL org.opencontainers.image.title="AuthCompanion"
5-
LABEL org.opencontainers.image.version="4.0.0-beta.1"
6-
LABEL org.opencontainers.image.description="An admin-friendly, User Management Server (with Passkeys & JWTs) - for seamless and secure integration of user authentication"
5+
LABEL org.opencontainers.image.version="5.0.0-beta.1"
6+
LABEL org.opencontainers.image.description="An admin-friendly, User Management Server (with Passkeys & JWTs)"
77
LABEL org.opencontainers.image.authors="Paul Fischer"
88
LABEL org.opencontainers.image.source=https://github.com/authcompanion/authcompanion2
99

10-
# update packages, to reduce the risk of vulnerabilities
11-
RUN apt-get update && apt-get upgrade -y && apt-get autoclean -y && apt-get autoremove -y
10+
WORKDIR /app
1211

13-
# set a non-privileged user to use when running this image
14-
RUN groupadd -r nodejs && useradd -g nodejs -s /bin/bash -d /home/nodejs -m nodejs
15-
USER nodejs
16-
# set the right (secure) folder permissions
17-
RUN mkdir -p /home/nodejs/app/node_modules /home/nodejs/app/authdata && chown -R nodejs:nodejs /home/nodejs/app
12+
COPY package*.json ./
13+
RUN npm install --include=dev
14+
COPY . .
15+
RUN npm run build
1816

19-
WORKDIR /home/nodejs/app
17+
# Stage 2: Production stage
18+
FROM --platform=linux/arm64 node:22-slim
2019

21-
# set default node env
22-
ARG NODE_ENV=production
23-
ENV NODE_ENV=${NODE_ENV}
20+
RUN groupadd -r nodejs && \
21+
useradd -g nodejs -s /bin/bash -d /home/nodejs -m nodejs && \
22+
mkdir -p /home/nodejs/app && \
23+
chown -R nodejs:nodejs /home/nodejs/app
2424

25-
ENV NPM_CONFIG_LOGLEVEL=warn
25+
RUN mkdir -p /data && \
26+
chown nodejs:nodejs /data && \
27+
chmod 755 /data
2628

27-
# copy project definition/dependencies files, for better reuse of layers
28-
COPY --chown=nodejs:nodejs package*.json ./
29-
30-
# install dependencies here, for better reuse of layers
31-
RUN npm install
29+
WORKDIR /home/nodejs/app
3230

33-
# copy all sources in the container (exclusions in .dockerignore file)
34-
COPY --chown=nodejs:nodejs . .
31+
COPY --from=builder --chown=nodejs:nodejs /app .
3532

36-
# Stage 2: Create a minimal image for ARM64v8
37-
FROM arm64v8/node:18-slim
33+
ENV NODE_ENV=production
34+
ENV NPM_CONFIG_LOGLEVEL=warn
3835

39-
WORKDIR /home/nodejs/app
36+
RUN npm prune --omit=dev && \
37+
npm cache clean --force
4038

41-
# Copy the application files from the builder stage
42-
COPY --from=builder /home/nodejs/app .
39+
USER nodejs
4340

44-
# Exposed port/s
4541
EXPOSE 3002
4642

47-
# Add an healthcheck, useful
48-
# Healthcheck with curl, but not recommended
49-
# HEALTHCHECK CMD curl --fail http://localhost:8000/health || exit 1
50-
# Healthcheck by calling the additional script exposed by the plugin
51-
# HEALTHCHECK --interval=30s --timeout=10s --start-period=5s CMD npm run healthcheck-manual
52-
53-
# Entrypoint and command
54-
CMD [ "node", "server.js" ]
43+
CMD [ "node", "server.js" ]

README.md

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,22 @@
1717
<img alt="GitHub stars" src="https://img.shields.io/github/stars/authcompanion/authcompanion2">
1818
</a>
1919
<a href="https://nodejs.org/en/">
20-
<img src="https://img.shields.io/badge/node-v20.11.0-green?logo=node.js"/>
20+
<img src="https://img.shields.io/badge/node-v22-green?logo=node.js"/>
2121
</a>
2222
<a href="https://github.com/authcompanion/authcompanion2/tags">
2323
<img src="https://img.shields.io/github/v/release/authcompanion/authcompanion2?color=purple&include_prereleases&style=flat-square"/>
2424
</a>
2525

2626
</div>
2727
<br />
28-
<p align="center"> Useful Links: <a href="https://docs.authcompanion.com/"> Documentation</a> | <a href="https://github.com/authcompanion/authcompanion2/blob/main/CHANGELOG.md"> CHANGELOG</a> | <a href="https://demo.authcompanion.com/v1/web/login"> Demo Site</a> | <a rel="me" href="https://hachyderm.io/@paulfish"> Follow on Mastodon</a>
28+
<p align="center"> Useful Links: <a href="https://docs.authcompanion.com/"> Documentation</a> | <a href="https://github.com/authcompanion/authcompanion2/blob/main/CHANGELOG.md"> CHANGELOG</a> | <a href="https://demo.authcompanion.com/login"> Demo Site</a> | <a rel="me" href="https://hachyderm.io/@paulfish"> Follow progress on Mastodon</a>
2929
</p>
3030

3131
---
3232

3333
## Hot topics
3434

35-
- Our documentation now includes 2 new [.rest files](https://github.com/authcompanion/authcompanion2/tree/main/tools) that utilize the VS Code [REST Client plugin](https://marketplace.visualstudio.com/items?itemName=humao.rest-client) to simplify API testing and provide clear examples of Authcompanion's admin and authentication APIs.
36-
- New Support for Postgres when storing user accounts + New Login & Registration Web Form Styling - [#22](https://github.com/authcompanion/authcompanion2/pull/22) [Done]
37-
- A Refresh of the Admin Dashboard Design - [#21](https://github.com/authcompanion/authcompanion2/pull/21) [Done]
35+
- We've added full OpenAPI 3.0 specification integration. Access the interactive documentation at: http://localhost:3002/docs/api when running the AuthC Server. Also refresh all of the site documentation for better clarity and instruction.
3836

3937
## Introduction
4038

@@ -44,7 +42,7 @@ With AuthC you can:
4442

4543
- Securely handle the registration, login, logout, and account recovery of user accounts.
4644
- Generate and verify [JWTs](https://jwt.io/introduction), a token used for your user's session and authenticating them into your web application's backend APIs.
47-
- Manage Users via a self-service Dashboard and confidently store and own your web application's user accounts, on your terms.
45+
- Manage users via a self-service Dashboard and confidently store and own your web application's user accounts, on premises.
4846
- Help users create accounts and login with a passkey on their mobile device (aka passwordless) or by using traditional username/passwords instead.
4947

5048
| Login Screen | Registration Screen |
@@ -59,7 +57,7 @@ The instructions below will launch the default server for exploring the features
5957

6058
Pre-requirement:
6159

62-
- [Node.js](http://nodejs.org) **version >=18.13**
60+
- [Node.js](http://nodejs.org) **version >=22**
6361

6462
Clone the repo if you haven't done so, and install dependencies using this
6563
command:
@@ -171,13 +169,12 @@ Have a look through the [Integration Guide](https://docs.authcompanion.com/guide
171169

172170
The RESTful Authentication API powers the Web Forms by which users authenticate into your web app. It's important to note that the web forms alone doesn't cover every authentication flow for your users. For example: refreshing an expired access token would require interacting with AuthC's APIs in addition to using the Web Froms.
173171

174-
For more information about the Authentication API check out the docs here: [Auth API](https://docs.authcompanion.com/guide/authapi.html)
175-
176172
### Admin API
177173

178174
The Admin API helps an administrator to manage the users of their web application. It provides a range of functions through which administrators can programatially create, edit, and delete user accounts. The Admin API is also natively used by the Admin Dashboard.
179175

180-
For more information about the Admin API check out the docs here: [Admin API](https://docs.authcompanion.com/guide/adminapi.html)
176+
- **Try the API:** Open [http://localhost:3002/docs/api](http://localhost:3002/docs/api) in your browser while the AuthC server is running.
177+
- **Interactive Documentation:** The documentation UI allows you to try endpoints, inspect request/response schemas, and view detailed requirements.
181178

182179
---
183180

0 commit comments

Comments
 (0)