mirror of
https://github.com/binwiederhier/ntfy.git
synced 2025-05-20 05:48:21 +02:00
Move to package
This commit is contained in:
parent
b908f07355
commit
f388fd9c90
4 changed files with 59 additions and 50 deletions
auth
36
auth/auth.go
Normal file
36
auth/auth.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
package auth
|
||||
|
||||
import "errors"
|
||||
|
||||
// auth is a generic interface to implement password-based authentication and authorization
|
||||
type Auth interface {
|
||||
Authenticate(user, pass string) (*User, error)
|
||||
Authorize(user *User, topic string, perm Permission) error
|
||||
}
|
||||
|
||||
type User struct {
|
||||
Name string
|
||||
Role Role
|
||||
}
|
||||
|
||||
type Permission int
|
||||
|
||||
const (
|
||||
PermissionRead = Permission(1)
|
||||
PermissionWrite = Permission(2)
|
||||
)
|
||||
|
||||
type Role string
|
||||
|
||||
const (
|
||||
RoleAdmin = Role("admin")
|
||||
RoleUser = Role("user")
|
||||
RoleNone = Role("none")
|
||||
)
|
||||
|
||||
var Everyone = &User{
|
||||
Name: "",
|
||||
Role: RoleNone,
|
||||
}
|
||||
|
||||
var ErrUnauthorized = errors.New("unauthorized")
|
Loading…
Add table
Add a link
Reference in a new issue