Skip to content

Commit addb356

Browse files
committed
GITBOOK-30: No subject
1 parent 00b25d7 commit addb356

24 files changed

+655
-215
lines changed

docs/development/deployment/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ docker-compose up server
3131
```
3232

3333
{% hint style="info" %}
34-
To change the Authority server configuration change the** local.env **file
34+
To change the Authority server configuration change the **local.env** file
3535
{% endhint %}
3636

3737
```yaml

docs/development/deployment/configuration.md

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,5 @@
22

33
All server settings are defined using environment variables
44

5-
| | | |
6-
| ------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------- |
7-
| **Environment Variable** | **Default Value** | **Description** |
8-
| **CRYSTAL\_ENV** | Development | |
9-
| **CRYSTAL\_LOG\_SOURCES** | "\*" | |
10-
| **CRYSTAL\_LOG\_LEVEL** | debug | |
11-
| **CRYSTAL\_WORKERS** | 4 | the number of CPU cores to use |
12-
| **PORT** | 4000 | |
13-
| **PORT\_REUSE** | true | |
14-
| **HOST** | 0.0;0.0 | Binds the server to a particular ip address on the host machine |
15-
| **DATABASE\_URL** | postgres://auth\_user:auth\_pass@db:5432/authority\_db?initial\_pool\_size=10\&checkout\_timeout=3P | PostgreSQL database connection URL |
16-
| **SECRET\_KEY** | secret\_key | The encryption key to use signed JWTs |
17-
| **CODE\_TTL** | 5 | Duration in seconds |
18-
| **ACCESS\_TOKEN\_TTL** | 60 | Duration in seconds |
19-
| **TEMPLATES\_PATH** | ./public/templates | |
20-
| **SESSION\_KEY** | session\_id | |
21-
| **BASE\_URL** | [http://localhost:4000](http://localhost:4000) | |
22-
| **DEVICE\_CODE\_TTL** | 300 | Duration in seconds |
23-
| **SSL\_CERT** | "" | |
24-
| **SSL\_KEY** | "" | |
25-
| **SSL\_CA** | "" | |
26-
| **SSL\_MODE** | "" | |
5+
<table><thead><tr><th width="254.33333333333331"></th><th></th><th></th></tr></thead><tbody><tr><td><strong>Environment Variable</strong></td><td><strong>Default Value</strong></td><td><strong>Description</strong></td></tr><tr><td><strong>CRYSTAL_ENV</strong></td><td>Development</td><td></td></tr><tr><td><strong>CRYSTAL_LOG_SOURCES</strong></td><td>"*"</td><td></td></tr><tr><td><strong>CRYSTAL_LOG_LEVEL</strong></td><td>debug</td><td></td></tr><tr><td><strong>CRYSTAL_WORKERS</strong></td><td>4</td><td>the number of CPU cores to use</td></tr><tr><td><strong>PORT</strong></td><td>4000</td><td></td></tr><tr><td><strong>PORT_REUSE</strong></td><td>true</td><td></td></tr><tr><td><strong>HOST</strong></td><td>0.0;0.0</td><td>Binds the server to a particular ip address on the host machine</td></tr><tr><td><strong>DATABASE_URL</strong></td><td>postgres://auth_user:auth_pass@db:5432/authority_db?initial_pool_size=10&#x26;checkout_timeout=3P</td><td>PostgreSQL database connection URL</td></tr><tr><td><strong>SECRET_KEY</strong></td><td>secret_key</td><td>The encryption key to use signed JWTs</td></tr><tr><td><strong>CODE_TTL</strong></td><td>5</td><td>Duration in seconds</td></tr><tr><td><strong>ACCESS_TOKEN_TTL</strong></td><td>60</td><td>Duration in seconds</td></tr><tr><td><strong>TEMPLATES_PATH</strong></td><td>./public/templates</td><td></td></tr><tr><td><strong>SESSION_KEY</strong></td><td>session_id</td><td></td></tr><tr><td><strong>BASE_URL</strong></td><td><a href="http://localhost:4000">http://localhost:4000</a></td><td></td></tr><tr><td><strong>DEVICE_CODE_TTL</strong></td><td>300</td><td>Duration in seconds</td></tr><tr><td><strong>SSL_CERT</strong></td><td>""</td><td></td></tr><tr><td><strong>SSL_KEY</strong></td><td>""</td><td></td></tr><tr><td><strong>SSL_CA</strong></td><td>""</td><td></td></tr><tr><td><strong>SSL_MODE</strong></td><td>""</td><td></td></tr></tbody></table>
276

docs/development/requirements.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
This project requires
44

5-
* **Crystal Language - **find the installation instructions here** **[https://crystal-lang.org/install/](https://crystal-lang.org/install/)
6-
* **Git - **[https://git-scm.com/book/en/v2/Getting-Started-Installing-Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
5+
* **Crystal Language -** find the installation instructions here [https://crystal-lang.org/install/](https://crystal-lang.org/install/)
6+
* **Git -** [https://git-scm.com/book/en/v2/Getting-Started-Installing-Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
77
* **PostgreSQL -** [https://www.postgresql.org/docs/current/tutorial-install.html](https://www.postgresql.org/docs/current/tutorial-install.html)
8-
* **Docker and Docker-Compose **- [https://docs.docker.com/engine/install/](https://docs.docker.com/engine/install/)
8+
* **Docker and Docker-Compose** - [https://docs.docker.com/engine/install/](https://docs.docker.com/engine/install/)
99
* **Geckodriver** - Needed for specs [https://www.softwaretestinghelp.com/geckodriver-selenium-tutorial/](https://www.softwaretestinghelp.com/geckodriver-selenium-tutorial/)

docs/development/specs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The project specifications can be found in the specs directory. Use the director
44

55
**Running Specs**
66

7-
If you have all the requirements installed, running the specs should be fairly simple.** Run the following commands to run the specs locally**
7+
If you have all the requirements installed, running the specs should be fairly simple. **Run the following commands to run the specs locally**
88

99
```bash
1010
shards build server

docs/development/user-interface.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ A template contains **variables** and/or **expressions**, which get replaced wit
2424
Below is a minimal template that illustrates a few basics using the default Jinja configuration. We will cover the details later in this document:
2525

2626
```django
27+
{% raw %}
2728
{% extends "layout.html" %}
2829
{% set title = "Signin" %}
2930
@@ -52,6 +53,7 @@ Below is a minimal template that illustrates a few basics using the default Jinj
5253
<div class="text-center small">Don't have an account? <a href="/register">Sign up</a></div>
5354
</main>
5455
{% endblock %}
56+
{% endraw %}
5557
```
5658

5759
{% hint style="info" %}

docs/README.md renamed to docs/docs/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ The Authority implements five grants for acquiring an access token:
4343

4444
#### Explore the implementations
4545

46-
{% content-ref url="reference/oauth-2-api/" %}
47-
[oauth-2-api](reference/oauth-2-api/)
46+
{% content-ref url="../reference/oauth-2-api/" %}
47+
[oauth-2-api](../reference/oauth-2-api/)
4848
{% endcontent-ref %}
4949

5050
The following RFCs are implemented:

docs/docs/SUMMARY.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Table of contents
2+
3+
* [Introduction](README.md)
4+
* [In Action](../in-action.md)
5+
* [Performance at Scale](../performance-at-scale.md)
6+
* [Roadmap / Features](../roadmap-features.md)
7+
8+
## Getting Started
9+
10+
* [Introduction](getting-started/introduction.md)
11+
* [Installation](getting-started/installation.md)
12+
* [Configuration Overview](getting-started/configuration-overview.md)
13+
14+
## Authentication
15+
16+
* [Authentication Guide](authentication/authentication-guide.md)
17+
* [API Documentation](authentication/api-documentation.md)
18+
* [Customizing Authentication](authentication/customizing-authentication.md)
19+
20+
## Security & Error Handling
21+
22+
* [Security Considerations](security-and-error-handling/security-considerations.md)
23+
* [Error Handling & Troubleshooting](security-and-error-handling/error-handling-and-troubleshooting.md)
24+
25+
## Providers
26+
27+
* [Client Providers](providers/client-providers.md)
28+
* [Owner Providers](providers/owner-providers.md)
29+
30+
## API Endpoints
31+
32+
* [API Endpoints](api-endpoints/api-endpoints.md)
33+
34+
## DEVELOPMENT
35+
36+
* [Requirements](../development/requirements.md)
37+
* [Database](../development/database.md)
38+
* [User Interface](../development/user-interface.md)
39+
* [Specs](../development/specs.md)
40+
* [Deployment](../development/deployment/README.md)
41+
* [Environment Variables](../development/deployment/configuration.md)
42+
43+
## Reference
44+
45+
* [OAuth Terms](../reference/oauth-terms.md)
46+
* [OAuth 2 Grant Flows](../reference/oauth-2-api/README.md)
47+
* [Device Flow](../reference/oauth-2-api/device-flow.md)
48+
* [Authorization Flow](../reference/oauth-2-api/authorization-flow.md)
49+
* [Client Credentials Flow](../reference/oauth-2-api/client-credentials.md)
50+
* [Refreshing Access Tokens](../reference/oauth-2-api/refreshing-access-tokens.md)
51+
* [Access Token Response](../reference/oauth-2-api/access-token-response.md)
52+
* [Json Web Tokens](../reference/oauth-2-api/json-web-tokens.md)
53+
* [Legacy: Implicit grant](../reference/oauth-2-api/implicit-grant.md)
54+
* [Legacy: Password](../reference/oauth-2-api/password.md)
55+
* [Open ID Connect](../reference/open-id-connect/README.md)
56+
* [Configuration](../reference/open-id-connect/configuration.md)
57+
* [Registering Clients](../reference/open-id-connect/registering-clients.md)
58+
* [User Info](../reference/open-id-connect/user-info.md)
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
# API Endpoints
2+
3+
This section documents all the available API endpoints in the Authority project. Each endpoint serves a specific purpose, such as managing OAuth clients, handling user sessions, or authorizing users.
4+
5+
### 1. Clients Endpoints
6+
7+
The `clients` endpoints manage OAuth clients that represent applications interacting with the Authority system.
8+
9+
* `POST /clients`: Create a new OAuth client.
10+
11+
Example Request:
12+
13+
```json
14+
{
15+
"name": "My App",
16+
"redirect_uri": "https://myapp.com/callback"
17+
}
18+
```
19+
20+
Example Response:
21+
22+
```json
23+
{
24+
"client_id": "abc123",
25+
"client_secret": "xyz789"
26+
}
27+
```
28+
* `GET /clients`: Retrieve a list of registered OAuth clients.
29+
30+
\
31+
Example Response:
32+
33+
```json
34+
[
35+
{
36+
"client_id": "abc123",
37+
"name": "My App",
38+
"redirect_uri": "https://myapp.com/callback"
39+
}
40+
]
41+
```
42+
43+
### 2. Owner Endpoints
44+
45+
The `owner` endpoints manage resource owners, allowing the Authority system to verify and manage access to resources owned by users.
46+
47+
* `GET /owner`: Retrieve information about the authenticated resource owner.
48+
49+
Example Response:
50+
51+
```json
52+
{
53+
"id": 1,
54+
"name": "John Doe",
55+
"email": "johndoe@example.com"
56+
}
57+
```
58+
59+
### 3. Sessions Endpoints
60+
61+
The `sessions` endpoints manage user sessions, including login and logout functionality.
62+
63+
* `POST /sessions/login`: Authenticate a user and create a session.
64+
65+
Example Request:
66+
67+
```json
68+
{
69+
"email": "user@example.com",
70+
"password": "password123"
71+
}
72+
```
73+
74+
Example Response:
75+
76+
```json
77+
{
78+
"access_token": "token123"
79+
}
80+
```
81+
* `POST /sessions/logout`: Log out the authenticated user and invalidate the session.
82+
83+
Example Response:
84+
85+
```json
86+
{
87+
"message": "Logged out successfully"
88+
}
89+
```
90+
91+
### 4. Authorize Endpoints
92+
93+
The `authorize` endpoints manage the OAuth authorization flow.
94+
95+
* `GET /authorize`: Redirect users to the OAuth provider for authorization.
96+
* Example Response: Redirects the user to the OAuth provider's login page.
97+
* `POST /authorize`: Handle the authorization code returned by the OAuth provider and exchange it for an access token.
98+
99+
Example Request:
100+
101+
```json
102+
{
103+
"authorization_code": "code123"
104+
}
105+
```
106+
107+
Example Response:
108+
109+
```json
110+
{
111+
"access_token": "token123"
112+
}
113+
```
114+
115+
### 5. Device Endpoints
116+
117+
The `device` endpoints manage device-specific interactions, such as registering or authenticating devices.
118+
119+
* `POST /device/register`: Register a new device.
120+
121+
Example Request:
122+
123+
```json
124+
{
125+
"device_id": "device123",
126+
"device_name": "John's Phone"
127+
}
128+
```
129+
130+
Example Response:
131+
132+
```json
133+
{
134+
"message": "Device registered successfully"
135+
}
136+
```
137+
138+
### 6. Access Token Endpoints
139+
140+
The `access_token` endpoints handle the management of access tokens, including issuing, refreshing, and revoking tokens.
141+
142+
* `POST /access_token`: Exchange an authorization code for an access token.
143+
144+
Example Request:
145+
146+
```json
147+
{
148+
"authorization_code": "code123"
149+
}
150+
```
151+
152+
Example Response:
153+
154+
```json
155+
{
156+
"access_token": "token123",
157+
"expires_in": 3600
158+
}
159+
```
160+
* `POST /access_token/revoke`: Revoke an access token.
161+
162+
Example Request:
163+
164+
```json
165+
{
166+
"access_token": "token123"
167+
}
168+
```
169+
170+
Example Response:
171+
172+
```json
173+
{
174+
"message": "Access token revoked"
175+
}
176+
```
177+
178+
### 7. Health Check
179+
180+
The `health_check.cr` endpoint is used to check the health of the Authority service.
181+
182+
* `GET /health_check`: Returns the status of the service.
183+
184+
Example Response:
185+
186+
```json
187+
{
188+
"status": "healthy"
189+
}
190+
```
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# API Documentation
2+
3+
Authority exposes several API endpoints for authentication. Below are some key endpoints:
4+
5+
* `POST /auth/login`: Authenticate a user and obtain a token.
6+
* `GET /auth/user`: Retrieve authenticated user details.
7+
* `POST /auth/logout`: Log out a user.
8+
9+
Each endpoint accepts and returns JSON data. Ensure that you include the correct OAuth token in the Authorization header for protected routes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Authentication Guide
2+
3+
Authority provides a simple yet flexible authentication system using OAuth.
4+
5+
### Setting up OAuth
6+
7+
1. Register your application with the desired OAuth provider.
8+
2. Obtain the client ID and client secret.
9+
3. Set these in the environment variables `OAUTH_CLIENT_ID` and `OAUTH_CLIENT_SECRET`.
10+
11+
### OAuth Flow
12+
13+
* Users will be redirected to the OAuth provider for authentication.
14+
* Once authenticated, the provider will return an authorization code.
15+
* This code can be exchanged for an access token, which can be used for further API requests.

0 commit comments

Comments
 (0)