Skip to content

Commit

Permalink
api key roles
Browse files Browse the repository at this point in the history
  • Loading branch information
dhawton committed Nov 4, 2023
1 parent e50c9e2 commit bfa2ec0
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion pkg/gin/middleware/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package auth

import (
"encoding/json"
"net/http"
"regexp"

Expand All @@ -34,7 +35,7 @@ import (

var (
log = logger.Logger.WithField("component", "middleware/auth")
tokenHeader = regexp.MustCompile(`^Token\s+(.+)$`)
tokenHeader = regexp.MustCompile(`^[tT]oken\s+(.+)$`)
)

func Auth(c *gin.Context) {
Expand Down Expand Up @@ -79,6 +80,19 @@ func Auth(c *gin.Context) {
}
}

// Setup roles for API Key
roles := []*models.Role{}
rawroles := []string{}
err = json.Unmarshal([]byte(apikey.Roles), &rawroles)
if err != nil {
log.Infof("Roles for API Key %s are invalid: %s", apikey.Key, err)
}
for _, r := range rawroles {
roles = append(roles, &models.Role{
Name: r,
})
}

user := &models.User{
CID: 1000,
FirstName: "Automation",
Expand All @@ -89,6 +103,7 @@ func Auth(c *gin.Context) {
RatingID: rating.ID,
Rating: *rating,
DiscordID: "",
Roles: roles,
RosterJoinDate: &apikey.CreatedAt,
CreatedAt: apikey.CreatedAt,
UpdatedAt: apikey.CreatedAt,
Expand Down

0 comments on commit bfa2ec0

Please sign in to comment.