question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

documentation of how to handle Authorization

See original GitHub issue

Story

I’m want to be able to send user authorization token that can modify the GraphQL context


When using subscriptions-transport-ws I could generate the GraphQL Context using the onConnect helper

https://github.com/sibelius/relay-workshop/blob/master/packages/server/src/index.ts#L30

import { SubscriptionServer } from 'subscriptions-transport-ws';

SubscriptionServer.create(
    {
      onConnect: async (connectionParams: ConnectionParams) => {
        const { user } = await getUser(connectionParams?.authorization);

        return getContext({ user });
      },
      // eslint-disable-next-line
      onDisconnect: () => console.log('Client subscription disconnected!'),
      execute,
      subscribe,
      schema,
    },
    {
      server,
      path: '/subscriptions',
    },
  );

When using this package, we need to pass context on server creating that we won’t be able to modify context based on use authorization token

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:6
  • Comments:31 (16 by maintainers)

github_iconTop GitHub Comments

2reactions
sibeliuscommented, Oct 23, 2020

should this be another recipe?

2reactions
enisdenjocommented, Oct 23, 2020

I personally like performing authorization on every subscription request (in onSubscribe). In cases where you’re using token based auth, running a check on every operation request guarantees expiry detection or manipulation prevention.

Read more comments on GitHub >

github_iconTop Results From Across the Web

API authentication and authorization - Idratherbewriting.com
In this section, you'll learn more about authentication and authorization and what you should focus on in documentation.
Read more >
Authorization of documents and folders in a process - IBM
You can assign various authorization levels to process documents and folders, depending on the user role for the process instance.
Read more >
Authentication vs. Authorization - Auth0
In simple terms, authentication is the process of verifying who a user is, while authorization is the process of verifying what they have...
Read more >
Introduction to authorization in ASP.NET Core | Microsoft Learn
Authorization refers to the process that determines what a user is able to do. For example, an administrative user is allowed to create...
Read more >
Authorization - HTTP - MDN Web Docs - Mozilla
The HTTP Authorization request header can be used to provide credentials that authenticate a user agent with a server, allowing access to a ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found