Skip to content

Commit 201ca39

Browse files
committed
Updated scopes
1 parent 1c8812e commit 201ca39

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

pkg/handler/auth/client/client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func Test_client_003(t *testing.T) {
7878
func Test_client_004(t *testing.T) {
7979
assert := assert.New(t)
8080
opts := []client.ClientOpt{
81-
client.OptTrace(os.Stderr, true),
81+
client.OptTrace(os.Stderr, false),
8282
}
8383
if token := GetToken(t); token != "" {
8484
opts = append(opts, client.OptReqToken(client.Token{

pkg/handler/auth/middleware.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
// Packages
99
"github.com/mutablelogic/go-server"
10+
"github.com/mutablelogic/go-server/pkg/handler/router"
1011
"github.com/mutablelogic/go-server/pkg/httpresponse"
1112
)
1213

@@ -52,13 +53,12 @@ func (middleware *auth) Wrap(ctx context.Context, next http.HandlerFunc) http.Ha
5253
} else if !token.IsValid() {
5354
authorized = false
5455
} else if token.IsScope(ScopeRoot) {
55-
// Allow
56-
} else {
57-
// TODO: Get scope for the route
58-
var allowedScopes = []string{}
59-
if token.IsScope(allowedScopes...) {
60-
authorized = true
61-
}
56+
// Allow - token is a super-user token
57+
} else if allowedScopes := router.Scope(r.Context()); len(allowedScopes) == 0 {
58+
// Allow - no scopes have been defined on this endpoint
59+
} else if !token.IsScope(allowedScopes...) {
60+
// Deny - token does not have the required scopes
61+
authorized = false
6262
}
6363

6464
// Return unauthorized if token is not found or not valid

0 commit comments

Comments
 (0)