Skip to content

Commit 6ceddfa

Browse files
committed
auth
1 parent 6f85b4e commit 6ceddfa

2 files changed

Lines changed: 85 additions & 8 deletions

File tree

docs/advanced-usage/authentication.md

Lines changed: 84 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,48 @@
44
This documentation is still being written and the features are under development. Please check back later for updates.
55
:::
66

7-
## How to Authenticate Your API Requests
7+
GameVault supports two primary authentication methods:
88

9-
Most API requests require authentication using a JSON Web Token (JWT). Include this token in the `Authorization` header of each request in the following format:
9+
1. **Bearer Token (JWT)** – for users logging in interactively. (The GameVault Client uses this method.)
10+
2. **API-Key** – for machine-to-machine and automated use cases.
11+
12+
This page shows you how to authenticate API requests using one of these methods.
13+
14+
Additionally this page provides details on [how to set up SSO (Single Sign-On)](#setting-up-oauth2-authentication-single-sign-on) via OAuth2, which allows users to authenticate using third-party identity providers like Google, Microsoft, Keycloak, etc.
15+
16+
## Bearer Token (JWT) Authentication
17+
18+
JWT is the default method for user-based authentication. Include your access token in the `Authorization` header like so:
1019

1120
```http
12-
Authorization: Bearer <your_token>
21+
Authorization: Bearer <your_access_token>
1322
```
1423

1524
### Generating Tokens
1625

17-
You can generate a Bearer token using one of the `login` endpoints:
26+
You can generate a Bearer token using one of the login endpoints:
27+
28+
- **Basic Authentication:**
29+
If enabled in your [server configuration](../server-docs/configuration.md#auth), authenticate via:
30+
31+
```http
32+
POST /api/auth/basic/login
33+
```
34+
35+
with your username and password. A user needs to be registered first using the registration endpoint.
36+
37+
- **OAuth2 Authentication:**
38+
If [OAuth2](#setting-up-oauth2-authentication-single-sign-on) is enabled in your [server configuration](../server-docs/configuration.md#auth), authenticate via:
39+
40+
```http
41+
GET /api/auth/oauth2/login
42+
```
1843

19-
- **Basic Authentication:** If Basic Authentication is enabled, authenticate via `POST /api/auth/basic/login` with your username and password.
20-
- **OAuth2 Authentication:** If [OAuth2 authentication](#setting-up-oauth2-authentication-single-sign-on) is enabled, authenticate via `GET /api/auth/oauth2/login` through your configured identity provider.
44+
through your configured identity provider. This will automatically register the user on the server if they don't already exist.
45+
46+
On success, both methods return an `access_token` and `refresh_token`. You can use the access token for authenticated requests to the GameVault API. The refresh token can be used to request a new access token when the current one expires.
47+
48+
### Token Expiration
2149

2250
Generated access tokens are valid for **5 minutes**, and refresh tokens for **30 days**. These durations can be adjusted on the [Configuration](../server-docs/configuration.md) page.
2351

@@ -29,6 +57,55 @@ When your access token expires, request a new token pair using your refresh toke
2957

3058
You can revoke a token by calling the `POST /api/auth/revoke` endpoint with your refresh token. This will effectively log out the user, by blocking future token refreshes.
3159

60+
## API-Key Authentication (Machine-to-Machine)
61+
62+
GameVault also supports API-key-based authentication. This is perfect for bots, automation, and service-to-service calls—no need for login sessions.
63+
64+
### Enabling API Key Support
65+
66+
To enable API-Key authentication, set the following environment variable:
67+
68+
```env
69+
AUTH_API_KEY_ENABLED=true
70+
```
71+
72+
### How to obtain an API Key
73+
74+
1. **Register a user and fetch their API Key**
75+
Register a user and use their Bearer token to fetch their API key via:
76+
77+
```http
78+
GET /api/users/me
79+
```
80+
81+
Example response:
82+
83+
```json
84+
{
85+
"id": "4",
86+
"username": "gvbot_infra",
87+
"api_key": "a1b2c3d4e5..." // this is your API key
88+
}
89+
```
90+
91+
:::tip You can hide Bots
92+
You can hide bot accounts from users by prefixing their usernames with `gvbot_`.
93+
:::
94+
95+
### Making Authenticated API Requests
96+
97+
Include your API-key in the request headers like so:
98+
99+
```http
100+
X-Api-Key: a1b2c3d4e5...
101+
```
102+
103+
### Notes
104+
105+
- API keys do **not expire**, handle them carefully
106+
- API keys currently **can not be revoked or changed**
107+
- API keys are **user-bound** and inherit that user's permissions.
108+
32109
## Setting Up OAuth2 Authentication (Single Sign-On)
33110

34111
Setting up single sign-on (SSO) using OAuth2 authentication for GameVault requires an identity provider (e.g. Google, Authelia, Keycloak, Microsoft, Discord, etc.).
@@ -54,7 +131,7 @@ Setting up single sign-on (SSO) using OAuth2 authentication for GameVault requir
54131

55132
### Debugging OAuth2 Authentication
56133

57-
- Set the environment variable `SERVER_LOG_LEVEL` environment variable to `debug` to receive detailed logs about the authentication process.
134+
You can set the environment variable `SERVER_LOG_LEVEL` environment variable to `debug` to receive detailed logs about the authentication process.
58135

59136
### Limitations
60137

docs/server-docs/websockets.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ For server owners who wish to disable activities, it's as simple as setting the
3535

3636
## Security
3737

38-
Each user is assigned a randomly generated Socket Secret that they can retrieve at `/api/users/me`. This secret must be included in the headers (X-Socket-Secret) of every subsequent Socket.IO Handshake request to the server.
38+
Each user is assigned a randomly generated API-Key, which they can retrieve at `/api/users/me`. This api-key must be included in the headers (X-Api-Key) of every subsequent Socket.IO Handshake request to the server.

0 commit comments

Comments
 (0)