examples icon indicating copy to clipboard operation
examples copied to clipboard

Example of authenticate on subscription

Open alexewsv opened this issue 1 year ago • 3 comments

hi all,

I've tried with example using axum and token from header with query and mutation works well. but I do not know how to do with subscription. Can you give a hint? thank you

alexewsv avatar Nov 26 '24 09:11 alexewsv

I've tried with example token from header but it seems not work image

alexewsv avatar Nov 27 '24 01:11 alexewsv

@alexewsv For subscription is a little different. On the browser we can't set headers when creating a websocket connection. You can check this page for a more detailed explanation on it. So, for sending a token to a subscription you could send it as the initial parameters of the subscription. This is showed on this example. On the example we register the on_connection_init callback function. This function will be called when a new connections is created and will check the token

mzaniolo avatar Sep 08 '25 14:09 mzaniolo

@alexewsv For subscription is a little different. On the browser we can't set headers when creating a websocket connection. You can check this page for a more detailed explanation on it. So, for sending a token to a subscription you could send it as the initial parameters of the subscription. This is showed on this example. On the example we register the on_connection_init callback function. This function will be called when a new connections is created and will check the token

Many thank your response. I'll check it soon.

alexewsv avatar Sep 30 '25 02:09 alexewsv