Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Redis Password Input #45

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ PORT=8080
HOST=0.0.0.0
# The URI used for connecting to redis
REDIS_URI=redis:6379
# The Password used for connecting to redis (leave blank if no password)
REDIS_PASS=

# URL that the root of the API will redirect to.
# The site specified here HAS TO link to the source code (including your modificiations, if applicable),
Expand Down
1 change: 1 addition & 0 deletions globals/globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var (
PORT = os.Getenv("PORT")

REDIS_URI = os.Getenv("REDIS_URI")
REDIS_PASS = os.Getenv("REDIS_PASS")

ROOT_REDIRECT = os.Getenv("ROOT_REDIRECT")

Expand Down
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ func requireAuth(c *fiber.Ctx) error {
"error": "Invalid authorization",
})
} else if err != nil {
if err.Error() == "ERR invalid password" || err.Error() == "NOAUTH Authentication required." {
return c.Status(401).JSON(&fiber.Map{
"error": "Redis authentication failed",
})
}
panic(err)
}

Expand Down Expand Up @@ -114,6 +119,7 @@ func main() {

g.RDB = redis.NewClient(&redis.Options{
Addr: g.REDIS_URI,
Password: g.REDIS_PASS,
})

if os.Getenv("PROMETHEUS") == "true" {
Expand Down
5 changes: 5 additions & 0 deletions routes/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ func GETOAuthCallback(c *fiber.Ctx) error {
secret = hex.EncodeToString(key)
g.RDB.Set(c.Context(), "secrets:"+util.Hash(g.PEPPER_SECRETS+userId), secret, 0)
} else if err != nil {
if err.Error() == "ERR invalid password" || err.Error() == "NOAUTH Authentication required." {
return c.Status(401).JSON(&fiber.Map{
"error": "Redis password is incorrect or missing!",
})
}
panic(err)
}

Expand Down