Hi,
We’re having some problems with combining the @secret
and @auth
directives which may very well be our lack of understanding.
We have the following type in a GraphQL schema to reproduce the problem:
type User @secret(field: "password") @auth(
query: {
rule: """
query ($user: String!) {
queryUser(filter: { username: { eq: $user } }) {
__typename
}
}
"""
}
)
{
username: String! @id
name: String!
}
(The actual @auth
query-rule is not that important here but in the example above should allow only a caller with the “user” JWT claim set to the username
of the node to see the information in it).
Our application uses self-registration so any user should be able to register a User without a JWT token. This works fine since there is no rule for the add
case in the @auth
-directive:
POST /graphql (without JWT in request)
mutation {
addUser(input: [{
username: "emily",
password: "password",
name: "Emily Blunt"
}]) {
numUids
}
}
gives:
{
"data": {
"addUser": {
"numUids": 1
}
}
}
Now, since the @secret
password is not included during querying, and since the username is marked as the @id
of the node we expected that we would be able to invoke the auto-generated checkUserPassword
like so:
POST /graphql (without JWT in request)
{
checkUserPassword (username: "emily", password: "password") {
__typename
}
}
without getting blocked by the @auth
query-rule. But instead we get the following server error (also displayed in the Alpha log):
"errors": [
{
"message": "Dgraph query failed because Dgraph execution failed because line 3 column 11: Expected Left round brackets. Got: lex.Item [6] \"{\" at 3:11"
}
],
"data": {
"checkUserPassword": null
}
Removing the @auth
directive allows checkUserPassword
to return. With a proper JWT token in the request we can also invoke checkUserPassword
.
Since adding a new User and logging in is done without a JWT we don’t quite see how we can protect the User
type with an @auth
directive while at the same time allow our external @remote
service to call checkUserPassword
in order to generate a JWT for further GraphQL queries?
Thanks for your time.