More work on stuff

This commit is contained in:
Caleb Gardner
2024-06-28 07:04:10 -05:00
parent 5db8692ec8
commit 5af5de7719
8 changed files with 34 additions and 24 deletions
+12 -1
View File
@@ -14,13 +14,24 @@ var (
ErrTokenUnauthorized = errors.New("token present but invalid")
)
type ApiKey struct {
Perm map[string]bool `json:"perm" bson:"perm"`
ID string `json:"id" bson:"_id" valkey:",key"`
AppID string `json:"appID" bson:"appID"`
Death int64 `json:"death" bson:"death"`
}
func (k ApiKey) GetID() string {
return k.ID
}
type ParsedHeader struct {
User *ReqestUser
Key *ApiKey
}
// Parses the X-API-Key and Authorization headers. If the API Key provided but invalid (either due to expiring or isn't found), ErrApiKeyUnauthorized is returned.
// If the Authorization header is present but invalid, ErrTokenUnauthorized is part of the returned error (check with errors.Is).
// If the Authorization header is present but invalid, ErrTokenUnauthorized is returned.
// NOTE: An invalid apiKey will cause a nil return, but a invalid token will not. Token parsing is only
func (b *Backend) ParseHeader(r *http.Request) (*ParsedHeader, error) {
out := &ParsedHeader{}
-12
View File
@@ -1,12 +0,0 @@
package backend
type ApiKey struct {
Perm map[string]bool `json:"perm" bson:"perm"`
ID string `json:"id" bson:"_id" valkey:",key"`
AppID string `json:"appID" bson:"appID"`
Death int64 `json:"death" bson:"death"`
}
func (k ApiKey) GetID() string {
return k.ID
}