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

Add additional headers to every request #167

Closed
jonjon0815 opened this issue Jul 24, 2024 · 9 comments
Closed

Add additional headers to every request #167

jonjon0815 opened this issue Jul 24, 2024 · 9 comments
Labels
enhancement New feature or request

Comments

@jonjon0815
Copy link

String? url = "https://xxxx";
String? key = "xxxxxx";

Dictionary<String, String> keys = new Dictionary<String, String>
{
       { "CF-Access-Client-Id", "xxxx.access" },
       { "CF-Access-Client-Secret", "xxxxxx" }
};

var options = new Supabase.SupabaseOptions
{
        AutoConnectRealtime = false,
        Headers = keys
};

supabase = new Supabase.Client(url, key, options);
await supabase.InitializeAsync();

I have set up a Supabase instance behind Cloudflare. Now I need to pass additional headers with every request. I already tried with the code above. This doesn't seem to be working. Does anyone have an idea how I could achieve this?

@jonjon0815 jonjon0815 added the enhancement New feature or request label Jul 24, 2024
@Pjort
Copy link
Contributor

Pjort commented Jul 25, 2024

I have exactly the same issue.

I have also tried:

options.Headers.Add({"CF-Access-Client-Secret", "xxxxxx" );

Please tell me if you manage to get a work around working.

@acupofjose
Copy link
Collaborator

This is actually missing as a feature at the moment. It would just take a small adjustment to GetAuthHeaders here. I’m away from my computer at the moment, so if you’re willing to PR, happy to have one!

@Pjort
Copy link
Contributor

Pjort commented Jul 25, 2024

This is actually missing as a feature at the moment. It would just take a small adjustment to GetAuthHeaders here. I’m away from my computer at the moment, so if you’re willing to PR, happy to have one!

I have made a PR: #168

@Pjort
Copy link
Contributor

Pjort commented Jul 26, 2024

The new version sems to have solved most of the issues I had, and I can set whatever custom header I need.

But for real time channels using the .On(ListenType.All, (sender, change) it seems it isn't sending the header. But I am still trying to locate if it is on client or server side this problem is located.

@acupofjose
Copy link
Collaborator

Since Realtime goes through Websockets, a header is only sent to establish an initial connection, it wouldn't be sent on every request

@Pjort
Copy link
Contributor

Pjort commented Jul 26, 2024

Yes I realized whenever I wrote it.

I looked into the realtime module.

From what I could tell the ws lib used is https://github.com/Marfusios/websocket-client

It has a SetRequestHeader method on ClientWebSocket.

But in the realtime module the WebsocketClient is used. I haven't spent the time figuring out the difference. But I just wanted to give me findings on the matter.

@acupofjose
Copy link
Collaborator

Oh! I apologize - I stand corrected. We actually don't pass any headers to the realtime client. All of the authorization is handled from inside the websocket connection. But that's a feature we can add in.

acupofjose added a commit to supabase-community/realtime-csharp that referenced this issue Jul 26, 2024
…ecifying `GetHeaders` on the `RealtimeClient` which are included on the initial request to the server to establish websocket connection.
@acupofjose
Copy link
Collaborator

Available in 1.1.1

@Pjort
Copy link
Contributor

Pjort commented Jul 29, 2024

I am using the SupabasTables method .On

public async Task<RealtimeChannel> On(ListenType listenType, IRealtimeChannel.PostgresChangesHandler handler)

And it seems to be calling the ConnectAsync() method
https://github.com/supabase-community/realtime-csharp/blob/973cdc20fa5d79438615f7b242d3268fef88de30/Realtime/Client.cs#L131

But it seems like the headers arn't getting applied from my testing. But I might be hitting the limitations of what is possible using headers and RLS.

RLS: (current_setting('request.headers'::text, true))::json ->> 'user_api_key'::text

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants