From 30cea5cc3a1b8cd42606692e1985528f937c83c2 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 6 Jul 2023 08:54:31 +0000 Subject: [PATCH] server: fix error message on missing grant in Access The error returned when a token is missing a required grant would be "Access denied for invalid auth method" which is confusing. Fix this with a more accurate error message. --- server/directives.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/directives.go b/server/directives.go index 26135b47d670dd27728199a041f7482a54838466..6740674e3074bfd64629d7cb8073cf1029b001dd 100644 --- a/server/directives.go +++ b/server/directives.go @@ -64,9 +64,10 @@ func Access(ctx context.Context, obj interface{}, next graphql.Resolver, } fallthrough case auth.AUTH_OAUTH2: - if authctx.Grants.Has(scope, kind) { - return next(ctx) + if !authctx.Grants.Has(scope, kind) { + return nil, fmt.Errorf("Access denied, missing %v:%v grant", scope, kind) } + return next(ctx) case auth.AUTH_ANON_INTERNAL: return nil, fmt.Errorf("Access denied for internal anonymous auth") default: