Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions packages/Supabase/Supabase.Tests/SupabaseClientCompositionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,17 @@ public void SupabaseClient_ShouldPreferSessionTokenOverApiKey_GivenActiveSession
"an active session's access token must take precedence over the api key as the bearer");
}

[TestMethod]
public void SupabaseClient_ShouldOmitAuthorizationOnRealtimePath_GivenActiveSession()
{
var client = UrlClient();
var auth = Substitute.For<IGotrueClient<User, Session>>();
auth.CurrentSession.Returns(new Session { AccessToken = "session-token" });
client.Auth = auth;
client.Realtime.GetHeaders!().Should().NotContainKey("Authorization",
"hosted Realtime rejects a user JWT on the websocket upgrade, the token goes in the channel join");
}

private static Supabase.Client NewKeyClient(string key) =>
new("http://localhost", key, new SupabaseOptions { AutoConnectRealtime = false });

Expand All @@ -355,8 +366,6 @@ public void SupabaseClient_ShouldOmitBearerOnFunctionsPath_GivenNewFormatKeyAndN
[TestMethod]
public void SupabaseClient_ShouldStillSendKeyAsBearerOnDatabasePath_GivenNewFormatKeyAndNoSession()
{
// Database/Storage/Realtime/auth keep the key on both headers — the gateway accepts it because
// the Bearer value exactly equals the apikey value. Only the Functions path is special-cased.
NewKeyClient("sb_publishable_abc123").Postgrest.GetHeaders!().Should().ContainKey("Authorization")
.WhoseValue.Should().Be("Bearer sb_publishable_abc123");
}
Expand Down
7 changes: 6 additions & 1 deletion packages/Supabase/Supabase/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,12 @@ public Client(string supabaseUrl, string? supabaseKey, SupabaseOptions? options
WebSocketFactory = this.options.WebSocketFactory
};
this.realtime = new Realtime.Client(realtimeUrl, realtimeOptions);
this.realtime.GetHeaders = () => this.GetAuthHeaders();
this.realtime.GetHeaders = () =>
{
var headers = this.GetAuthHeaders();
headers.Remove("Authorization");
return headers;
};
this.functions = new Functions.Client(functionsUrl, options: new Functions.ClientOptions
{
HttpClient = this.options.HttpClient,
Expand Down
Loading