I got an No Auth Token error when alter the schema with dgraph4j client

my dgraph verison is v20.07.0 and dgraph4j version is v20.03.0.
I added a “–auth_token hello” option to alpha.

I added a header for my grpc request according to this document

like this:

//add alpha auth token.
Metadata metadata = new Metadata();
metadata.put(
    Metadata.Key.of("X-Dgraph-AuthToken", Metadata.ASCII_STRING_MARSHALLER), "hello");
stub = MetadataUtils.attachHeaders(stub, metadata);

But when I alter the schema, I still get this error.

java.lang.RuntimeException: UNKNOWN: No Auth Token found. Token needed for Alter operations.

I tried to do the same with curl, and there was no problem.

As in docs, it is auth-token and not X-Dgraph-AuthToken when using it in gRPC metadata.
For HTTP headers, it is X-Dgraph-AuthToken.

See here for reference.

1 Like

It’s ok now. Thank you very much.