GraphQL API and utilities for the rpdata project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
711 B

  1. package models
  2. // A Key contains a JWT secret and the limitations of it. There are two types of
  3. // keys, single-user keys and wildcard keys. The former is used to authenticate
  4. // a single user (e.g. the logbot) through an API while the latter is only for
  5. // services that can be trusted to perform its own authentication (a frontend).
  6. type Key struct {
  7. ID string `bson:"_id"`
  8. Name string `bson:"name"`
  9. User string `bson:"user"`
  10. Secret string `bson:"secret"`
  11. }
  12. // ValidForUser returns true if the key's user is the same as
  13. // the user, or it's a wildcard key.
  14. func (key *Key) ValidForUser(user string) bool {
  15. return key.User == user || key.User == "*"
  16. }
  17. type KeyFilter struct {
  18. UserID *string
  19. }