Implement scopes
This commit is contained in:
parent
be07ac5d83
commit
064ae2f564
15 changed files with 232 additions and 137 deletions
32
internal/dis/component/auth/scopes/user.go
Normal file
32
internal/dis/component/auth/scopes/user.go
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
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 UserLoggedIn struct {
|
||||
component.Base
|
||||
Dependencies struct {
|
||||
Auth *auth.Auth
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
_ component.ScopeProvider = (*UserLoggedIn)(nil)
|
||||
)
|
||||
|
||||
func (*UserLoggedIn) Scope() component.ScopeInfo {
|
||||
return component.ScopeInfo{
|
||||
Scope: component.ScopeUserLoggedIn,
|
||||
Description: "session has an associated user",
|
||||
TakesParam: false,
|
||||
}
|
||||
}
|
||||
|
||||
func (iu *UserLoggedIn) HasScope(param string, r *http.Request) (bool, error) {
|
||||
user, err := iu.Dependencies.Auth.UserOf(r)
|
||||
return user != nil, err
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue