Implement basic API scoping
This commit is contained in:
parent
064ae2f564
commit
9db53d39c4
21 changed files with 519 additions and 264 deletions
|
|
@ -18,9 +18,13 @@ var (
|
|||
_ component.ScopeProvider = (*UserLoggedIn)(nil)
|
||||
)
|
||||
|
||||
const (
|
||||
ScopeAdminLoggedIn Scope = "login.admin"
|
||||
)
|
||||
|
||||
func (*AdminLoggedIn) Scope() component.ScopeInfo {
|
||||
return component.ScopeInfo{
|
||||
Scope: component.ScopeAdminLoggedIn,
|
||||
Scope: ScopeAdminLoggedIn,
|
||||
Description: "session has a signed in admin",
|
||||
DeniedMessage: "user must be signed into an admin account with TOTP enabled",
|
||||
TakesParam: false,
|
||||
|
|
|
|||
38
internal/dis/component/auth/scopes/instances.go
Normal file
38
internal/dis/component/auth/scopes/instances.go
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
package scopes
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/auth"
|
||||
)
|
||||
|
||||
type ListInstancesScope struct {
|
||||
component.Base
|
||||
Dependencies struct {
|
||||
Auth *auth.Auth
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
_ component.ScopeProvider = (*ListInstancesScope)(nil)
|
||||
)
|
||||
|
||||
const (
|
||||
ScopeInstanceDirectory Scope = "instances.directory"
|
||||
)
|
||||
|
||||
func (*ListInstancesScope) Scope() component.ScopeInfo {
|
||||
return component.ScopeInfo{
|
||||
Scope: ScopeInstanceDirectory,
|
||||
Description: "get a public directory of instances",
|
||||
DeniedMessage: "",
|
||||
TakesParam: false,
|
||||
}
|
||||
}
|
||||
|
||||
func (lis *ListInstancesScope) HasScope(param string, r *http.Request) (bool, error) {
|
||||
// TODO: at the moment everyone has this permission
|
||||
// this should change in the future!
|
||||
return true, nil
|
||||
}
|
||||
37
internal/dis/component/auth/scopes/news.go
Normal file
37
internal/dis/component/auth/scopes/news.go
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
package scopes
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/auth"
|
||||
)
|
||||
|
||||
type ListNewsScope struct {
|
||||
component.Base
|
||||
Dependencies struct {
|
||||
Auth *auth.Auth
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
_ component.ScopeProvider = (*ListNewsScope)(nil)
|
||||
)
|
||||
|
||||
const (
|
||||
ScopeListNews Scope = "news.list"
|
||||
)
|
||||
|
||||
func (*ListNewsScope) Scope() component.ScopeInfo {
|
||||
return component.ScopeInfo{
|
||||
Scope: ScopeListNews,
|
||||
Description: "list news items",
|
||||
DeniedMessage: "",
|
||||
TakesParam: false,
|
||||
}
|
||||
}
|
||||
|
||||
func (lns *ListNewsScope) HasScope(param string, r *http.Request) (bool, error) {
|
||||
// TODO: at the moment everyone has this permission
|
||||
return true, nil
|
||||
}
|
||||
6
internal/dis/component/auth/scopes/scopes.go
Normal file
6
internal/dis/component/auth/scopes/scopes.go
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// Package scopes implements and provides scopes used by the API
|
||||
package scopes
|
||||
|
||||
import "github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
||||
|
||||
type Scope = component.Scope
|
||||
|
|
@ -18,9 +18,13 @@ var (
|
|||
_ component.ScopeProvider = (*UserLoggedIn)(nil)
|
||||
)
|
||||
|
||||
const (
|
||||
ScopeUserLoggedIn Scope = "login.user"
|
||||
)
|
||||
|
||||
func (*UserLoggedIn) Scope() component.ScopeInfo {
|
||||
return component.ScopeInfo{
|
||||
Scope: component.ScopeUserLoggedIn,
|
||||
Scope: ScopeUserLoggedIn,
|
||||
Description: "session has an associated user",
|
||||
TakesParam: false,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue