~bigbes/core-go

30cea5cc3a1b8cd42606692e1985528f937c83c2 — Simon Ser 3 years ago 43a2be1
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.
1 files changed, 3 insertions(+), 2 deletions(-)

M server/directives.go
M server/directives.go => server/directives.go +3 -2
@@ 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: