-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* renaming everything to go-rest-api * serve docs * adding favicons and docs * adding favicons and docs * improving docs * fixing logger * improving docs * adding unit tests * adding unit tests * adding more documentation and cache to the token middleware --------- Co-authored-by: Nico Bistolfi <[email protected]>
- Loading branch information
1 parent
7b25abc
commit 73a8322
Showing
57 changed files
with
1,738 additions
and
555 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
service: go-boilerplate | ||
service: go-rest-api | ||
frameworkVersion: ^3.0.0 | ||
|
||
plugins: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
label: Authentication | ||
position: 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Auth Middleware | ||
|
||
The Auth Middleware, defined in `auth.go`, is responsible for extracting authentication tokens from incoming requests. It supports multiple authentication methods to provide flexibility in how clients can authenticate. | ||
|
||
## Key Features | ||
|
||
- Checks multiple sources for authentication tokens | ||
- Supports different authentication methods | ||
- Sets extracted token information in the request context | ||
|
||
## Token Extraction Process | ||
|
||
1. Check the `Authorization` header | ||
2. If not found, check the `X-API-Key` header | ||
3. If still not found, check the `access_token` query parameter | ||
|
||
## Usage in Routes | ||
|
||
```go | ||
protected := r.Group("/api/v1") | ||
protected.Use(middleware.AuthMiddleware()) | ||
``` | ||
|
||
This middleware sets the stage for token validation, which is handled by the Token Middleware. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Environment Variables | ||
|
||
The authentication system uses environment variables for configuration. These variables allow for flexible deployment across different environments. | ||
|
||
## Key Environment Variables | ||
|
||
1. `TOKEN_URL` | ||
- Purpose: Specifies the URL of the external authentication service used for token validation. | ||
- Required: Yes | ||
- Example: `https://auth.example.com/validate` | ||
|
||
2. `TOKEN_CACHE_EXPIRY` | ||
- Purpose: Sets the expiration time for cached tokens. | ||
- Usage: Parsed in the `init()` function of `token.go` | ||
- Required: No (defaults to 5 minutes if not set) | ||
- Example: `15m` for 15 minutes, `1h` for 1 hour | ||
|
||
## Setting Environment Variables | ||
|
||
### In Development | ||
|
||
Use a `.env` file in the project root: | ||
|
||
``` | ||
TOKEN_URL=https://auth.example.com/validate | ||
TOKEN_CACHE_EXPIRY=10m | ||
``` | ||
|
||
### In Production | ||
|
||
Set environment variables according to your deployment platform: | ||
|
||
- Docker: Use the `-e` flag or `environment` section in docker-compose.yml | ||
- Kubernetes: Use `ConfigMap` and `Secret` resources | ||
- Cloud Platforms: Use the platform-specific method for setting environment variables |
Oops, something went wrong.