Skip to content

Commit

Permalink
Add QR code ID
Browse files Browse the repository at this point in the history
  • Loading branch information
jveski committed Nov 23, 2024
1 parent 0b863de commit c0e7787
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 5 additions & 2 deletions keycloak.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ func (k *keycloak) ensureToken(ctx context.Context) (*gocloak.JWT, error) {

type AccessUser struct {
UserID string `json:"userID"`
FobID int `json:"fobID"`
FobID int `json:"fobID,omitempty"`
QRID int `json:"qrID,omitempty"`
TTL int64 `json:"ttl"`
}

Expand All @@ -168,7 +169,8 @@ func newAccessUser(kcuser *gocloak.User) *AccessUser {

attr := *kcuser.Attributes
fobID, _ := strconv.Atoi(firstElOrZeroVal(attr["keyfobID"]))
if fobID == 0 {
qrID, _ := strconv.Atoi(firstElOrZeroVal(attr["qrID"]))
if fobID == 0 && qrID == 0 {
return nil
}
if firstElOrZeroVal(attr["buildingAccessApprover"]) == "" {
Expand All @@ -178,6 +180,7 @@ func newAccessUser(kcuser *gocloak.User) *AccessUser {
return &AccessUser{
UserID: *kcuser.ID,
FobID: fobID,
QRID: qrID,
TTL: (time.Hour * 24).Milliseconds(), // TODO: Load from keycloak
}
}
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func main() {
}

// TODO: Actually store these somewhere
slog.Info("received event", "timestamp", e.Timestamp, "personID", e.PersonID, "fobID", e.FobID, "authorized", e.Authorized)
slog.Info("received event", "timestamp", e.Timestamp, "personID", e.PersonID, "fobID", e.FobID, "qrID", e.QRID, "authorized", e.Authorized)
})

refresh := make(chan struct{}, 1)
Expand Down Expand Up @@ -121,5 +121,6 @@ type Event struct {
Timestamp int64 `json:"timestamp"`
PersonID string `json:"personID"`
FobID int64 `json:"fobID"`
QRID int64 `json:"qrID"`
Authorized bool `json:"authorized"`
}

0 comments on commit c0e7787

Please sign in to comment.