Does @withSubscription not work yet with @auth rules?

Sidenote, we probably need a subscription tag too in Discuss.

Saw the blog on Subscriptions today and was excited to give it a run for the money!

With a simple scheme it worked perfectly

type Message @withSubscription {
  id: ID!
  to: String!
  from: String!
  message: String!
}

However I need to also secure these so users only see their own messages of course, so just a simple test with the @auth directive fails.

type Message @withSubscription @auth(
  query: { rule: "{$USERROLE: { eq: \"USER\"}}" }
) {
  id: ID!
  to: String!
  from: String!
  message: String!
}
# Dgraph.Authorization {"VerificationKey":"super-secret","Header":"auth","Namespace":"https://mydomain.com/jwt/claims","Algo":"HS256"}

example header:

{ "auth":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE1OTIyMzkwMjIsImV4cCI6MTU5NzIzOTAyMiwiaHR0cHM6Ly9teWRvbWFpbi5jb20vand0L2NsYWltcyI6eyJVU0VSUk9MRSI6IlVTRVIifX0.pU61zHMOaz1ZJ7GCvJsHIRqKSwZe4RI5TVZywkaqkXM" }

Now this works for the basic query but with a subscription it just returns an empty data set, acts like it has not authority


Subscriptions are going to be pretty useless to me until they also work with auth rules. Maybe I am missing an auth rule for subscriptions? but seeing that a subscription is the same as a query I would think it would work with the same query rules.

1 Like

Which version of Dgraph are you using ?
Subscription with auth rules are pushed to master yesterday only!! and have to wait untill we push it into release.
You can try it on master branch untill then.
@pawan any idea when auth+subscriptions will be avaliable on release ?

1 Like

I was using standalone:master not sure how recent though, within the week. I will see if there is a newer image. And I can wait a little bit longer. I just jumped the gun

1 Like

This should be available on the latest master image and also the standalone image. Unfortunately it won’t make it to 20.07.0 which goes out next week. We plan to push it out as part of 20.07.1 which goes out next month.

1 Like

Did this make it in? Also trying to use subscription and auth like so

type Nex @withSubscription @auth(
    query: { rule:  "{ $isAuth: { eq: \"true\" } }"}
) {
    title: String! @id
}

And done :slight_smile:

1 Like

It should. I have not retested it since released.

Sorry I mean the feature to combine the two @auth and @withSubscription

Yes, thats available on Slash GraphQL and also master, 20.07.1 release.

3 posts were split to a new topic: Auth and Subscription How To