You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/advanced-usage/authentication.md
+84-7Lines changed: 84 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,20 +4,48 @@
4
4
This documentation is still being written and the features are under development. Please check back later for updates.
5
5
:::
6
6
7
-
## How to Authenticate Your API Requests
7
+
GameVault supports two primary authentication methods:
8
8
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:
10
19
11
20
```http
12
-
Authorization: Bearer <your_token>
21
+
Authorization: Bearer <your_access_token>
13
22
```
14
23
15
24
### Generating Tokens
16
25
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
+
```
43
+
44
+
through your configured identity provider. This will automatically register the user on the server if they don't already exist.
18
45
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.
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
21
49
22
50
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.
23
51
@@ -29,6 +57,55 @@ When your access token expires, request a new token pair using your refresh toke
29
57
30
58
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.
31
59
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
+
32
109
## Setting Up OAuth2 Authentication (Single Sign-On)
33
110
34
111
Setting up single sign-on (SSO) using OAuth2 authentication for GameVault requires an identity provider (e.g. Google, Authelia, Keycloak, Microsoft, Discord, etc.).
Copy file name to clipboardExpand all lines: docs/server-docs/websockets.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,4 +35,4 @@ For server owners who wish to disable activities, it's as simple as setting the
35
35
36
36
## Security
37
37
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