Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@Authorized in subscriptions #175

Closed
MichalLytek opened this issue Oct 21, 2018 · 3 comments · Fixed by #578
Closed

@Authorized in subscriptions #175

MichalLytek opened this issue Oct 21, 2018 · 3 comments · Fixed by #578
Assignees
Labels
Bug 🐛 Something isn't working Solved ✔️ The issue has been solved
Milestone

Comments

@MichalLytek
Copy link
Owner

Right now @Authorized in subscriptions cause that the autorization checker is called only when pubsub emit new event in selected topic (when subscription method body is called). But it should be called only during subscribe phase to reject unauthorized clients.

This would require some changes in creating middlewares stack that is applied only for resolvers. For now I will handle that case manually without exposing different kind of middlewares.

@MichalLytek MichalLytek added the Bug 🐛 Something isn't working label Oct 21, 2018
@MichalLytek MichalLytek added this to the 1.0.0 release milestone Oct 21, 2018
@MichalLytek MichalLytek self-assigned this Oct 21, 2018
@nudabagana
Copy link

nudabagana commented Mar 18, 2019

I would like to suggest a workaround for refusing connections in resolvers @19majkel94 :
first you make authorization in onConnect
(but don't reject the socket yet, just return the status)

const subscriptionServer = new SubscriptionServer({
  schema,
  execute,
  subscribe,
  onConnect(connectionParams) {
   // ... do authorization
  return { authorized: false }; // or true
  }
...

next off, when declaring your topic in subscribtion you can access the .authorized field:

  @Subscription({
    topics: ({ args, context, payload }) => {
      if (!context.authorized )
      {
          // this gives user error response and cancels subsribtion
          throw new AuthenticationError(`Unauthorized user cannot receive info from this socket`);
      }
      return SOME_TOPIC;
}
  })
  accountBalanceChangeTopic(
//...
}

throwing error inside topics ( or filters) results in socket connection being closed (and send a desired error to user).

@Adam-Burke
Copy link

Just wondering if I could get some information about whether this is still an issue and if so where it is in the pipeline?

@MichalLytek
Copy link
Owner Author

It's related to #200 and will be handled in the 1.0.0 milestone.

@MichalLytek MichalLytek added the Solved ✔️ The issue has been solved label Mar 14, 2020
@MichalLytek MichalLytek added Duplicate 🔑 This issue or pull request already exists and removed Solved ✔️ The issue has been solved labels Dec 30, 2020
@MichalLytek MichalLytek removed this from the 1.0.0 release milestone Dec 30, 2020
@MichalLytek MichalLytek added Solved ✔️ The issue has been solved and removed Duplicate 🔑 This issue or pull request already exists labels Dec 30, 2020
@MichalLytek MichalLytek added this to the 1.0.0 release milestone Dec 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐛 Something isn't working Solved ✔️ The issue has been solved
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants