From ca5a1331e172b1ae59b9e031adfc2ea6afca1bfc Mon Sep 17 00:00:00 2001 From: tr00d Date: Thu, 29 Oct 2026 15:21:30 +0100 Subject: [PATCH 1/2] feat(auth): fetch a custom OAuth/OIDC provider as an admin --- .../GetCustomProviderContractTests.cs | 110 ++++++++++++++++++ .../GetCustomProviderIdentifierTests.cs | 39 +++++++ .../GetCustomProviderTests.cs | 57 +++++++++ packages/Gotrue/Gotrue/AdminClient.cs | 5 + packages/Gotrue/Gotrue/Api.cs | 12 +- .../Gotrue/Interfaces/IGotrueAdminClient.cs | 25 ++++ .../Gotrue/Gotrue/Interfaces/IGotrueApi.cs | 11 ++ .../Gotrue/Gotrue/PublicAPI.Unshipped.txt | 4 + 8 files changed, 262 insertions(+), 1 deletion(-) create mode 100644 packages/Gotrue/Gotrue.Tests/GetCustomProvider/GetCustomProviderContractTests.cs create mode 100644 packages/Gotrue/Gotrue.Tests/GetCustomProvider/GetCustomProviderIdentifierTests.cs create mode 100644 packages/Gotrue/Gotrue.Tests/GetCustomProvider/GetCustomProviderTests.cs diff --git a/packages/Gotrue/Gotrue.Tests/GetCustomProvider/GetCustomProviderContractTests.cs b/packages/Gotrue/Gotrue.Tests/GetCustomProvider/GetCustomProviderContractTests.cs new file mode 100644 index 00000000..fda66c5b --- /dev/null +++ b/packages/Gotrue/Gotrue.Tests/GetCustomProvider/GetCustomProviderContractTests.cs @@ -0,0 +1,110 @@ +#region + +using System; +using System.Net; +using System.Net.Http; +using System.Threading; +using System.Threading.Tasks; +using FluentAssertions; +using Gotrue.Tests.Common; +using Gotrue.Tests.Support; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Supabase.Gotrue; +using Supabase.Gotrue.Common; +using Supabase.Gotrue.Exceptions; +using WireMock.Matchers; +using WireMock.RequestBuilders; +using WireMock.ResponseBuilders; + +#endregion + +namespace Gotrue.Tests.GetCustomProvider; + +/// +/// Pins the wire contract of fetching a custom OAuth/OIDC provider against a stubbed auth server: the route, the +/// service-role credentials, the response and failure mapping, and cancellation. +/// +[TestClass] +[TestCategory("Contract")] +public class GetCustomProviderContractTests +{ + private const string ServiceKey = "service-role-jwt"; + + private MockGotrueServer server = null!; + + [TestInitialize] + public void TestInitialize() => this.server = new MockGotrueServer(); + + [TestCleanup] + public void TestCleanup() => this.server.Dispose(); + + [TestMethod] + [DataRow("custom:mycompany")] + [DataRow("custom:my.company")] + public async Task GetCustomProviderAsync_ShouldFetchProviderByIdentifierWithServiceRoleCredentials(string identifier) + { + this.AnswerWith(HttpStatusCode.OK, CustomProviderResponses.Oidc); + await this.Admin.GetCustomProviderAsync(identifier); + this.server.VerifySingleReceivedRequest() + .WithMethod(HttpMethod.Get) + .WithPath($"/admin/custom-providers/{identifier}") + .WithHeader("Authorization", $"Bearer {ServiceKey}"); + } + + [TestMethod] + public async Task GetCustomProviderAsync_ShouldReturnProvider() + { + this.AnswerWith(HttpStatusCode.OK, CustomProviderResponses.OAuth2); + (await this.Admin.GetCustomProviderAsync("custom:customauth")).Should().BeEquivalentTo(new + { + Id = Guid.Parse("6ea7e0b6-ee41-4791-802c-ea0625ee8d6b"), + Type = CustomProviderType.OAuth2, + Identifier = "custom:customauth", + AuthorizationUrl = new Uri("https://provider.example.com/oauth/authorize"), + }, "the auth server answers 200 with the stored provider, as in its CustomOAuthProviderSchema"); + } + + [TestMethod] + public async Task GetCustomProviderAsync_ShouldThrowCustomProviderNotFound_GivenUnknownIdentifier() + { + this.AnswerWith(HttpStatusCode.NotFound, """{"code":404,"error_code":"custom_provider_not_found","msg":"Custom OAuth provider not found"}"""); + var get = () => this.Admin.GetCustomProviderAsync("custom:unknown"); + await get.Should().ThrowExactlyAsync() + .Where(failure => failure.Reason == FailureHint.Reason.CustomProviderNotFound, + "the auth server answers 404 custom_provider_not_found when no provider has the identifier"); + } + + [TestMethod] + public async Task GetCustomProviderAsync_ShouldThrowGotrueException_GivenNullResponseBody() + { + this.AnswerWith(HttpStatusCode.OK, "null"); + var get = () => this.Admin.GetCustomProviderAsync("custom:mycompany"); + await get.Should().ThrowExactlyAsync().WithMessage("*returned no custom provider*", + "a 200 always carries the provider; anything else is a broken response, not a provider"); + } + + [TestMethod] + public void GetCustomProviderAsync_ShouldComplete_GivenCallerBlockingOnContextThatNeverRunsContinuations() + { + this.AnswerWith(HttpStatusCode.OK, CustomProviderResponses.OAuth2); + BlockingCaller.Completes(() => this.Admin.GetCustomProviderAsync("custom:customauth")).Should().BeTrue( + "a library must not resume on the caller's context: a UI thread blocking on the task would deadlock"); + } + + [TestMethod] + public async Task GetCustomProviderAsync_ShouldNotSendRequest_GivenCancelledToken() + { + using var cancelled = new CancellationTokenSource(); + cancelled.Cancel(); + var get = () => this.Admin.GetCustomProviderAsync("custom:mycompany", cancelled.Token); + await get.Should().ThrowAsync(); + this.server.CountReceivedRequests().Should().Be(0, "a cancelled token must stop the request before it reaches the wire"); + } + + private AdminClient Admin => new(ServiceKey, new ClientOptions { Url = this.server.Url }); + + private void AnswerWith(HttpStatusCode status, string body) => + this.server.Given(Request.Create().WithPath(new WildcardMatcher("/admin/custom-providers/*")).UsingGet()) + .RespondWith(Response.Create().WithStatusCode(status) + .WithHeader("Content-Type", "application/json").WithBody(body)); +} diff --git a/packages/Gotrue/Gotrue.Tests/GetCustomProvider/GetCustomProviderIdentifierTests.cs b/packages/Gotrue/Gotrue.Tests/GetCustomProvider/GetCustomProviderIdentifierTests.cs new file mode 100644 index 00000000..039018ef --- /dev/null +++ b/packages/Gotrue/Gotrue.Tests/GetCustomProvider/GetCustomProviderIdentifierTests.cs @@ -0,0 +1,39 @@ +#region + +using System; +using System.Threading.Tasks; +using FluentAssertions; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Supabase.Gotrue; + +#endregion + +namespace Gotrue.Tests.GetCustomProvider; + +/// +/// The identifier checks made before a lookup leaves the SDK: the custom: prefix the auth server requires, +/// and the characters that would change which route the request reaches. +/// +[TestClass] +[TestCategory("Unit")] +public class GetCustomProviderIdentifierTests +{ + private static readonly AdminClient Admin = new("service-role-jwt", new ClientOptions { Url = "http://localhost" }); + + [TestMethod] + public async Task GetCustomProviderAsync_ShouldThrowArgumentNull_GivenNullIdentifier() + { + var get = () => Admin.GetCustomProviderAsync(null!); + await get.Should().ThrowExactlyAsync().WithParameterName("identifier"); + } + + [TestMethod] + [DataRow("mycompany")] + [DataRow("custom:x/../../users/00000000-0000-0000-0000-000000000000")] + public async Task GetCustomProviderAsync_ShouldThrowArgument_GivenIdentifierItCannotRoute(string identifier) + { + var get = () => Admin.GetCustomProviderAsync(identifier); + await get.Should().ThrowExactlyAsync() + .WithParameterName("identifier", "the identifier is a path segment checked like the delete's: 'custom:' prefix, no route-changing characters"); + } +} diff --git a/packages/Gotrue/Gotrue.Tests/GetCustomProvider/GetCustomProviderTests.cs b/packages/Gotrue/Gotrue.Tests/GetCustomProvider/GetCustomProviderTests.cs new file mode 100644 index 00000000..08a123d0 --- /dev/null +++ b/packages/Gotrue/Gotrue.Tests/GetCustomProvider/GetCustomProviderTests.cs @@ -0,0 +1,57 @@ +#region + +using System; +using System.Threading.Tasks; +using FluentAssertions; +using Gotrue.Tests.Common; +using Gotrue.Tests.Support; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Supabase.Gotrue.Common; +using Supabase.Gotrue.Exceptions; + +#endregion + +namespace Gotrue.Tests.GetCustomProvider; + +/// +/// End-to-end lookup of a custom OAuth/OIDC provider by its identifier against the live stack. +/// +[TestClass] +[TestCategory("E2E")] +public class GetCustomProviderTests : CustomProviderAdminFixture +{ + [TestMethod] + public async Task GetCustomProviderAsync_ShouldReturnProvider() + { + await this.SeedProvider(); + (await this.Admin.GetCustomProviderAsync(this.Identifier)).Should().BeEquivalentTo(new + { + Type = CustomProviderType.OAuth2, + Identifier = this.Identifier, + Name = "E2E provider", + ClientId = "client-id", + AuthorizationUrl = new Uri("https://example.com/authorize"), + TokenUrl = new Uri("https://example.com/token"), + UserInfoUrl = new Uri("https://example.com/userinfo"), + }, "the provider is returned as it was registered"); + } + + [TestMethod] + public async Task GetCustomProviderAsync_ShouldThrowCustomProviderNotFound_GivenUnknownIdentifier() + { + var get = () => this.Admin.GetCustomProviderAsync(this.Identifier); + await get.Should().ThrowAsync() + .Where(failure => failure.Reason == FailureHint.Reason.CustomProviderNotFound, + "the auth server answers 404 custom_provider_not_found when no provider has the identifier"); + } + + [TestMethod] + public async Task GetCustomProviderAsync_ShouldThrowAdminTokenRequired_GivenNonAdminKey() + { + await this.SeedProvider(); + var get = () => TestClients.AdminAgainstCliStack(TestClients.CliAnonKey).GetCustomProviderAsync(this.Identifier); + await get.Should().ThrowAsync() + .Where(failure => failure.Reason == FailureHint.Reason.AdminTokenRequired, + "the auth server answers 403 not_admin to a key without the service_role claim"); + } +} diff --git a/packages/Gotrue/Gotrue/AdminClient.cs b/packages/Gotrue/Gotrue/AdminClient.cs index 1cc9b2ea..001da075 100644 --- a/packages/Gotrue/Gotrue/AdminClient.cs +++ b/packages/Gotrue/Gotrue/AdminClient.cs @@ -159,6 +159,11 @@ private static string RequireAccessToken(string accessToken) => public Task CreateCustomProviderAsync(NewCustomProvider provider, CustomProviderOptions? options = null, CancellationToken cancellationToken = default) => this.api.CreateCustomProviderAsync(this.serviceKey, provider, options, cancellationToken); + /// + [ImplementedCapability("auth.admin.get_provider")] + public Task GetCustomProviderAsync(string identifier, CancellationToken cancellationToken = default) => + this.api.GetCustomProviderAsync(this.serviceKey, identifier, cancellationToken); + /// public async Task Update(UserAttributes attributes) { diff --git a/packages/Gotrue/Gotrue/Api.cs b/packages/Gotrue/Gotrue/Api.cs index d4875a70..9d2d7a95 100644 --- a/packages/Gotrue/Gotrue/Api.cs +++ b/packages/Gotrue/Gotrue/Api.cs @@ -642,7 +642,7 @@ public ProviderAuthState GetUriForProvider(Provider provider, SignInOptions? opt /// public Task DeleteCustomProviderAsync(string jwt, string identifier, CancellationToken cancellationToken = default) => - this.MakeRequestAsync(HttpMethod.Delete, $"{this.Url}/admin/custom-providers/{CustomProviderIdentifier.EnsureRoutable(identifier)}", null, this.CreateAuthedRequestHeaders(jwt), cancellationToken); + this.MakeRequestAsync(HttpMethod.Delete, this.CustomProviderUrl(identifier), null, this.CreateAuthedRequestHeaders(jwt), cancellationToken); /// public async Task CreateCustomProviderAsync(string jwt, NewCustomProvider provider, CustomProviderOptions? options = null, CancellationToken cancellationToken = default) @@ -652,6 +652,16 @@ public async Task CreateCustomProviderAsync(string jwt, NewCusto return CustomProviderResponse.Read(created); } + /// + public async Task GetCustomProviderAsync(string jwt, string identifier, CancellationToken cancellationToken = default) + { + var provider = await this.MakeRequestAsync(HttpMethod.Get, this.CustomProviderUrl(identifier), null, this.CreateAuthedRequestHeaders(jwt), cancellationToken).ConfigureAwait(false); + return CustomProviderResponse.Read(provider); + } + + private string CustomProviderUrl(string identifier) => + $"{this.Url}/admin/custom-providers/{CustomProviderIdentifier.EnsureRoutable(identifier)}"; + /// public async Task LinkIdentity(string token, Provider provider, SignInOptions options) { diff --git a/packages/Gotrue/Gotrue/Interfaces/IGotrueAdminClient.cs b/packages/Gotrue/Gotrue/Interfaces/IGotrueAdminClient.cs index fbf0c7e2..02ea0418 100644 --- a/packages/Gotrue/Gotrue/Interfaces/IGotrueAdminClient.cs +++ b/packages/Gotrue/Gotrue/Interfaces/IGotrueAdminClient.cs @@ -194,4 +194,29 @@ public interface IGotrueAdminClient : IGettableHeaders /// /// Task CreateCustomProviderAsync(NewCustomProvider provider, CustomProviderOptions? options = null, CancellationToken cancellationToken = default); + + /// + /// Fetches a custom OAuth/OIDC provider by its identifier. Requires a full-access API key, such as the + /// service_role key: call it from a server, never from a client app. + /// + /// The provider identifier, starting with custom: (for example custom:mycompany). + /// Cancels the request. + /// The provider. Its client secret is never returned. + /// + /// The identifier lacks the custom: prefix or contains /, \, ?, # or %. + /// Nothing is sent. + /// + /// + /// The server rejected the request. is + /// when no provider has this identifier and + /// when the key is not a full-access key; + /// is feature_disabled when custom providers are disabled on the project. + /// + /// + /// + /// var admin = new AdminClient(serviceRoleKey, new ClientOptions { Url = authUrl }); + /// var provider = await admin.GetCustomProviderAsync("custom:mycompany"); + /// + /// + Task GetCustomProviderAsync(string identifier, CancellationToken cancellationToken = default); } diff --git a/packages/Gotrue/Gotrue/Interfaces/IGotrueApi.cs b/packages/Gotrue/Gotrue/Interfaces/IGotrueApi.cs index d3fa36d5..e15db13a 100644 --- a/packages/Gotrue/Gotrue/Interfaces/IGotrueApi.cs +++ b/packages/Gotrue/Gotrue/Interfaces/IGotrueApi.cs @@ -92,6 +92,17 @@ public interface IGotrueApi : IGettableHeaders /// The server rejected the request. Task CreateCustomProviderAsync(string jwt, NewCustomProvider provider, CustomProviderOptions? options = null, CancellationToken cancellationToken = default); + /// + /// Fetches a custom OAuth/OIDC provider by its identifier. + /// + /// A full-access API key, such as the service_role key. + /// The provider identifier, starting with custom:. + /// Cancels the request. + /// The provider. + /// The identifier lacks the custom: prefix or contains /, \, ?, # or %. + /// The server rejected the request. + Task GetCustomProviderAsync(string jwt, string identifier, CancellationToken cancellationToken = default); + /// /// Links an oauth identity to an existing user. /// diff --git a/packages/Gotrue/Gotrue/PublicAPI.Unshipped.txt b/packages/Gotrue/Gotrue/PublicAPI.Unshipped.txt index 2c0e4de1..7561530a 100644 --- a/packages/Gotrue/Gotrue/PublicAPI.Unshipped.txt +++ b/packages/Gotrue/Gotrue/PublicAPI.Unshipped.txt @@ -22,7 +22,9 @@ static Supabase.Gotrue.CreateCustomProvider.NewCustomProvider.Oidc(string! ident static Supabase.Gotrue.CreateCustomProvider.NewCustomProvider.operator !=(Supabase.Gotrue.CreateCustomProvider.NewCustomProvider? left, Supabase.Gotrue.CreateCustomProvider.NewCustomProvider? right) -> bool static Supabase.Gotrue.CreateCustomProvider.NewCustomProvider.operator ==(Supabase.Gotrue.CreateCustomProvider.NewCustomProvider? left, Supabase.Gotrue.CreateCustomProvider.NewCustomProvider? right) -> bool Supabase.Gotrue.AdminClient.CreateCustomProviderAsync(Supabase.Gotrue.CreateCustomProvider.NewCustomProvider! provider, Supabase.Gotrue.Common.CustomProviderOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task! +Supabase.Gotrue.AdminClient.GetCustomProviderAsync(string! identifier, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task! Supabase.Gotrue.Api.CreateCustomProviderAsync(string! jwt, Supabase.Gotrue.CreateCustomProvider.NewCustomProvider! provider, Supabase.Gotrue.Common.CustomProviderOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task! +Supabase.Gotrue.Api.GetCustomProviderAsync(string! jwt, string! identifier, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task! Supabase.Gotrue.Common.CustomProvider Supabase.Gotrue.Common.CustomProvider.$() -> Supabase.Gotrue.Common.CustomProvider! Supabase.Gotrue.Common.CustomProvider.AcceptableClientIds.get -> System.Collections.Generic.IReadOnlyList! @@ -137,8 +139,10 @@ Supabase.Gotrue.CreateCustomProvider.NewCustomProvider.TokenUrl.get -> System.Ur Supabase.Gotrue.CreateCustomProvider.NewCustomProvider.Type.get -> Supabase.Gotrue.Common.CustomProviderType Supabase.Gotrue.CreateCustomProvider.NewCustomProvider.UserInfoUrl.get -> System.Uri? Supabase.Gotrue.Interfaces.IGotrueAdminClient.CreateCustomProviderAsync(Supabase.Gotrue.CreateCustomProvider.NewCustomProvider! provider, Supabase.Gotrue.Common.CustomProviderOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task! +Supabase.Gotrue.Interfaces.IGotrueAdminClient.GetCustomProviderAsync(string! identifier, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task! Supabase.Gotrue.Interfaces.IGotrueApi.CreateCustomProviderAsync(string! jwt, Supabase.Gotrue.CreateCustomProvider.NewCustomProvider! provider, Supabase.Gotrue.Common.CustomProviderOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task! Supabase.Gotrue.AdminClient.SignOutAsync(string! accessToken, Supabase.Gotrue.Constants.SignOutScope scope = Supabase.Gotrue.Constants.SignOutScope.Global, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task! Supabase.Gotrue.Api.SignOutAsync(string! jwt, Supabase.Gotrue.Constants.SignOutScope scope = Supabase.Gotrue.Constants.SignOutScope.Global, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task! Supabase.Gotrue.Interfaces.IGotrueAdminClient.SignOutAsync(string! accessToken, Supabase.Gotrue.Constants.SignOutScope scope = Supabase.Gotrue.Constants.SignOutScope.Global, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task! Supabase.Gotrue.Interfaces.IGotrueApi.SignOutAsync(string! jwt, Supabase.Gotrue.Constants.SignOutScope scope = Supabase.Gotrue.Constants.SignOutScope.Global, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task! +Supabase.Gotrue.Interfaces.IGotrueApi.GetCustomProviderAsync(string! jwt, string! identifier, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task! From dfb631a2b1830dea0b1a09038a8c792dbf9026f1 Mon Sep 17 00:00:00 2001 From: tr00d Date: Thu, 29 Oct 2026 16:38:25 +0100 Subject: [PATCH 2/2] fix(auth): repair the master merge on the get-provider branch Drop the duplicated CreateCustomProviderAsync entry from PublicAPI.Unshipped.txt, restore the generated sdk-compliance.yaml entry for update_provider, keep the update member's doc comment intact, and remove a whitespace-only line. --- packages/Gotrue/Gotrue/AdminClient.cs | 10 ++-- packages/Gotrue/Gotrue/Api.cs | 14 +++--- .../Gotrue/Interfaces/IGotrueAdminClient.cs | 48 +++++++++---------- .../Gotrue/Gotrue/Interfaces/IGotrueApi.cs | 16 +++---- .../Gotrue/Gotrue/PublicAPI.Unshipped.txt | 5 +- sdk-compliance.yaml | 4 ++ 6 files changed, 50 insertions(+), 47 deletions(-) diff --git a/packages/Gotrue/Gotrue/AdminClient.cs b/packages/Gotrue/Gotrue/AdminClient.cs index a92436f4..0ebefa64 100644 --- a/packages/Gotrue/Gotrue/AdminClient.cs +++ b/packages/Gotrue/Gotrue/AdminClient.cs @@ -160,16 +160,16 @@ private static string RequireAccessToken(string accessToken) => public Task CreateCustomProviderAsync(NewCustomProvider provider, CustomProviderOptions? options = null, CancellationToken cancellationToken = default) => this.api.CreateCustomProviderAsync(this.serviceKey, provider, options, cancellationToken); - /// - [ImplementedCapability("auth.admin.get_provider")] - public Task GetCustomProviderAsync(string identifier, CancellationToken cancellationToken = default) => - this.api.GetCustomProviderAsync(this.serviceKey, identifier, cancellationToken); - /// [ImplementedCapability("auth.admin.update_provider")] public Task UpdateCustomProviderAsync(string identifier, CustomProviderChanges changes, CancellationToken cancellationToken = default) => this.api.UpdateCustomProviderAsync(this.serviceKey, identifier, changes, cancellationToken); + /// + [ImplementedCapability("auth.admin.get_provider")] + public Task GetCustomProviderAsync(string identifier, CancellationToken cancellationToken = default) => + this.api.GetCustomProviderAsync(this.serviceKey, identifier, cancellationToken); + /// public async Task Update(UserAttributes attributes) { diff --git a/packages/Gotrue/Gotrue/Api.cs b/packages/Gotrue/Gotrue/Api.cs index 2dc74c2b..251dca96 100644 --- a/packages/Gotrue/Gotrue/Api.cs +++ b/packages/Gotrue/Gotrue/Api.cs @@ -653,13 +653,6 @@ public async Task CreateCustomProviderAsync(string jwt, NewCusto return CustomProviderResponse.Read(created); } - /// - public async Task GetCustomProviderAsync(string jwt, string identifier, CancellationToken cancellationToken = default) - { - var provider = await this.MakeRequestAsync(HttpMethod.Get, this.CustomProviderUrl(identifier), null, this.CreateAuthedRequestHeaders(jwt), cancellationToken).ConfigureAwait(false); - return CustomProviderResponse.Read(provider); - } - /// public async Task UpdateCustomProviderAsync(string jwt, string identifier, CustomProviderChanges changes, CancellationToken cancellationToken = default) { @@ -668,6 +661,13 @@ public async Task UpdateCustomProviderAsync(string jwt, string i return CustomProviderResponse.Read(updated); } + /// + public async Task GetCustomProviderAsync(string jwt, string identifier, CancellationToken cancellationToken = default) + { + var provider = await this.MakeRequestAsync(HttpMethod.Get, this.CustomProviderUrl(identifier), null, this.CreateAuthedRequestHeaders(jwt), cancellationToken).ConfigureAwait(false); + return CustomProviderResponse.Read(provider); + } + private string CustomProviderUrl(string identifier) => $"{this.Url}/admin/custom-providers/{CustomProviderIdentifier.EnsureRoutable(identifier)}"; diff --git a/packages/Gotrue/Gotrue/Interfaces/IGotrueAdminClient.cs b/packages/Gotrue/Gotrue/Interfaces/IGotrueAdminClient.cs index a8600ff5..b17d9d6d 100644 --- a/packages/Gotrue/Gotrue/Interfaces/IGotrueAdminClient.cs +++ b/packages/Gotrue/Gotrue/Interfaces/IGotrueAdminClient.cs @@ -197,12 +197,15 @@ public interface IGotrueAdminClient : IGettableHeaders Task CreateCustomProviderAsync(NewCustomProvider provider, CustomProviderOptions? options = null, CancellationToken cancellationToken = default); /// - /// Fetches a custom OAuth/OIDC provider by its identifier. Requires a full-access API key, such as the - /// service_role key: call it from a server, never from a client app. + /// Updates a custom OAuth/OIDC provider. Only the members set on are sent; the others + /// keep their current value. Requires a full-access API key, such as the service_role key: call it from a server, + /// never from a client app. /// /// The provider identifier, starting with custom: (for example custom:mycompany). + /// The changes. An empty or blank value cannot clear a setting: the server reads it as unchanged. /// Cancels the request. - /// The provider. Its client secret is never returned. + /// The updated provider. + /// is null. Nothing is sent. /// /// The identifier lacks the custom: prefix or contains /, \, ?, # or %. /// Nothing is sent. @@ -211,25 +214,32 @@ public interface IGotrueAdminClient : IGettableHeaders /// The server rejected the request. is /// when no provider has this identifier and /// when the key is not a full-access key; - /// is feature_disabled when custom providers are disabled on the project. + /// is validation_failed when a setting is invalid (for + /// example a URL that is not HTTPS, or an OIDC issuer whose discovery document cannot be fetched) and + /// feature_disabled when custom providers are disabled on the project. /// /// /// + /// using Supabase.Gotrue.Common; + /// using Supabase.Gotrue.UpdateCustomProvider; + /// /// var admin = new AdminClient(serviceRoleKey, new ClientOptions { Url = authUrl }); - /// var provider = await admin.GetCustomProviderAsync("custom:mycompany"); + /// var updated = await admin.UpdateCustomProviderAsync("custom:mycompany", new CustomProviderChanges + /// { + /// Name = "My Company", + /// Options = new CustomProviderOptions { Enabled = false }, + /// }); /// /// - Task GetCustomProviderAsync(string identifier, CancellationToken cancellationToken = default); + Task UpdateCustomProviderAsync(string identifier, CustomProviderChanges changes, CancellationToken cancellationToken = default); /// - /// Updates a custom OAuth/OIDC provider. Only the members set on are sent; the others - /// keep their current value. Requires a full-access API key, such as the service_role key: call it from a server, - /// never from a client app. + /// Fetches a custom OAuth/OIDC provider by its identifier. Requires a full-access API key, such as the + /// service_role key: call it from a server, never from a client app. /// /// The provider identifier, starting with custom: (for example custom:mycompany). - /// The changes. An empty or blank value cannot clear a setting: the server reads it as unchanged. /// Cancels the request. - /// The updated provider. + /// The provider. Its client secret is never returned. /// /// The identifier lacks the custom: prefix or contains /, \, ?, # or %. /// Nothing is sent. @@ -238,23 +248,13 @@ public interface IGotrueAdminClient : IGettableHeaders /// The server rejected the request. is /// when no provider has this identifier and /// when the key is not a full-access key; - /// is null. Nothing is sent. - /// is validation_failed when a setting is invalid (for - /// example a URL that is not HTTPS, or an OIDC issuer whose discovery document cannot be fetched) and - /// feature_disabled when custom providers are disabled on the project. + /// is feature_disabled when custom providers are disabled on the project. /// /// /// - /// using Supabase.Gotrue.Common; - /// using Supabase.Gotrue.UpdateCustomProvider; - /// /// var admin = new AdminClient(serviceRoleKey, new ClientOptions { Url = authUrl }); - /// var updated = await admin.UpdateCustomProviderAsync("custom:mycompany", new CustomProviderChanges - /// { - /// Name = "My Company", - /// Options = new CustomProviderOptions { Enabled = false }, - /// }); + /// var provider = await admin.GetCustomProviderAsync("custom:mycompany"); /// /// - Task UpdateCustomProviderAsync(string identifier, CustomProviderChanges changes, CancellationToken cancellationToken = default); + Task GetCustomProviderAsync(string identifier, CancellationToken cancellationToken = default); } diff --git a/packages/Gotrue/Gotrue/Interfaces/IGotrueApi.cs b/packages/Gotrue/Gotrue/Interfaces/IGotrueApi.cs index 7d5f44f6..a463991a 100644 --- a/packages/Gotrue/Gotrue/Interfaces/IGotrueApi.cs +++ b/packages/Gotrue/Gotrue/Interfaces/IGotrueApi.cs @@ -94,28 +94,28 @@ public interface IGotrueApi : IGettableHeaders Task CreateCustomProviderAsync(string jwt, NewCustomProvider provider, CustomProviderOptions? options = null, CancellationToken cancellationToken = default); /// - /// Fetches a custom OAuth/OIDC provider by its identifier. + /// Updates a custom OAuth/OIDC provider. /// /// A full-access API key, such as the service_role key. /// The provider identifier, starting with custom:. + /// The changes; members left null keep their current value. /// Cancels the request. - /// The provider. + /// The updated provider. + /// is null. /// The identifier lacks the custom: prefix or contains /, \, ?, # or %. /// The server rejected the request. - Task GetCustomProviderAsync(string jwt, string identifier, CancellationToken cancellationToken = default); + Task UpdateCustomProviderAsync(string jwt, string identifier, CustomProviderChanges changes, CancellationToken cancellationToken = default); /// - /// Updates a custom OAuth/OIDC provider. + /// Fetches a custom OAuth/OIDC provider by its identifier. /// /// A full-access API key, such as the service_role key. /// The provider identifier, starting with custom:. - /// The changes; members left null keep their current value. /// Cancels the request. - /// The updated provider. - /// is null. + /// The provider. /// The identifier lacks the custom: prefix or contains /, \, ?, # or %. /// The server rejected the request. - Task UpdateCustomProviderAsync(string jwt, string identifier, CustomProviderChanges changes, CancellationToken cancellationToken = default); + Task GetCustomProviderAsync(string jwt, string identifier, CancellationToken cancellationToken = default); /// /// Links an oauth identity to an existing user. diff --git a/packages/Gotrue/Gotrue/PublicAPI.Unshipped.txt b/packages/Gotrue/Gotrue/PublicAPI.Unshipped.txt index c3f211cb..63c9a8a1 100644 --- a/packages/Gotrue/Gotrue/PublicAPI.Unshipped.txt +++ b/packages/Gotrue/Gotrue/PublicAPI.Unshipped.txt @@ -28,10 +28,9 @@ static Supabase.Gotrue.UpdateCustomProvider.CustomProviderChanges.operator !=(Su static Supabase.Gotrue.UpdateCustomProvider.CustomProviderChanges.operator ==(Supabase.Gotrue.UpdateCustomProvider.CustomProviderChanges? left, Supabase.Gotrue.UpdateCustomProvider.CustomProviderChanges? right) -> bool Supabase.Gotrue.AdminClient.CreateCustomProviderAsync(Supabase.Gotrue.CreateCustomProvider.NewCustomProvider! provider, Supabase.Gotrue.Common.CustomProviderOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task! Supabase.Gotrue.AdminClient.GetCustomProviderAsync(string! identifier, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task! -Supabase.Gotrue.Api.CreateCustomProviderAsync(string! jwt, Supabase.Gotrue.CreateCustomProvider.NewCustomProvider! provider, Supabase.Gotrue.Common.CustomProviderOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task! -Supabase.Gotrue.Api.GetCustomProviderAsync(string! jwt, string! identifier, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task! Supabase.Gotrue.AdminClient.UpdateCustomProviderAsync(string! identifier, Supabase.Gotrue.UpdateCustomProvider.CustomProviderChanges! changes, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task! Supabase.Gotrue.Api.CreateCustomProviderAsync(string! jwt, Supabase.Gotrue.CreateCustomProvider.NewCustomProvider! provider, Supabase.Gotrue.Common.CustomProviderOptions? options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task! +Supabase.Gotrue.Api.GetCustomProviderAsync(string! jwt, string! identifier, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task! Supabase.Gotrue.Api.UpdateCustomProviderAsync(string! jwt, string! identifier, Supabase.Gotrue.UpdateCustomProvider.CustomProviderChanges! changes, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task! Supabase.Gotrue.Common.CustomProvider Supabase.Gotrue.Common.CustomProvider.$() -> Supabase.Gotrue.Common.CustomProvider! @@ -153,8 +152,8 @@ Supabase.Gotrue.Interfaces.IGotrueApi.CreateCustomProviderAsync Supabase.Gotrue.AdminClient.SignOutAsync(string! accessToken, Supabase.Gotrue.Constants.SignOutScope scope = Supabase.Gotrue.Constants.SignOutScope.Global, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task! Supabase.Gotrue.Api.SignOutAsync(string! jwt, Supabase.Gotrue.Constants.SignOutScope scope = Supabase.Gotrue.Constants.SignOutScope.Global, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task! Supabase.Gotrue.Interfaces.IGotrueAdminClient.SignOutAsync(string! accessToken, Supabase.Gotrue.Constants.SignOutScope scope = Supabase.Gotrue.Constants.SignOutScope.Global, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task! -Supabase.Gotrue.Interfaces.IGotrueApi.SignOutAsync(string! jwt, Supabase.Gotrue.Constants.SignOutScope scope = Supabase.Gotrue.Constants.SignOutScope.Global, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task! Supabase.Gotrue.Interfaces.IGotrueApi.GetCustomProviderAsync(string! jwt, string! identifier, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task! +Supabase.Gotrue.Interfaces.IGotrueApi.SignOutAsync(string! jwt, Supabase.Gotrue.Constants.SignOutScope scope = Supabase.Gotrue.Constants.SignOutScope.Global, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task! Supabase.Gotrue.Interfaces.IGotrueApi.UpdateCustomProviderAsync(string! jwt, string! identifier, Supabase.Gotrue.UpdateCustomProvider.CustomProviderChanges! changes, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task! Supabase.Gotrue.UpdateCustomProvider.CustomProviderChanges Supabase.Gotrue.UpdateCustomProvider.CustomProviderChanges.$() -> Supabase.Gotrue.UpdateCustomProvider.CustomProviderChanges! diff --git a/sdk-compliance.yaml b/sdk-compliance.yaml index 5a77f021..a5615f26 100644 --- a/sdk-compliance.yaml +++ b/sdk-compliance.yaml @@ -181,6 +181,10 @@ features: status: implemented symbols: - AdminClient.SignOutAsync + auth.admin.update_provider: + status: implemented + symbols: + - AdminClient.UpdateCustomProviderAsync auth.admin.update_user: status: implemented symbols: