![]() |
VOOZH | about |
Supabase is migrating its packages to match the Nuget naming conventions.
dotnet add package gotrue-csharp --version 4.3.1
NuGet\Install-Package gotrue-csharp -Version 4.3.1
<PackageReference Include="gotrue-csharp" Version="4.3.1" />
<PackageVersion Include="gotrue-csharp" Version="4.3.1" />Directory.Packages.props
<PackageReference Include="gotrue-csharp" />Project file
paket add gotrue-csharp --version 4.3.1
#r "nuget: gotrue-csharp, 4.3.1"
#:package gotrue-csharp@4.3.1
#addin nuget:?package=gotrue-csharp&version=4.3.1Install as a Cake Addin
#tool nuget:?package=gotrue-csharp&version=4.3.1Install as a Cake Tool
<p align="center"> <img width="300" src=".github/supabase-gotrue.png"/> </p>
<p align="center"> <img src="https://github.com/supabase/gotrue-csharp/workflows/Build%20And%20Test/badge.svg"/> <a href="https://www.nuget.org/packages/gotrue-csharp/"> <img src="https://img.shields.io/badge/dynamic/json?color=green&label=Nuget%20Release&query=data[0].version&url=https%3A%2F%2Fazuresearch-usnc.nuget.org%2Fquery%3Fq%3Dpackageid%3Agotrue-csharp"/> </a> </p>
The Client works with Unity. You can find an example of a session persistence implementation for Unity at this gist.
The Client now better supports online/offline usage. The Client now has a simple boolean option "Online" which can be set to to false. This can be combined with the NetworkStatus class to allow the client to automatically go online & offline based on the device's network status.
To use this new NetworkStatus, add the following:
// Create the client
var client = new Client(new ClientOptions { AllowUnconfirmedUserSessions = true });
// Create the network status monitor
var status = new NetworkStatus();
// Tell the network status monitor to update the client's online status
status.Client = client;
// Start the network status monitor
await status.StartAsync();
// rest of the usual client configuration
Only the stateful Client supports this feature, and only for the managed user sessions. Admin JWT methods and the stateless client are not affected.
By default, this change will not affect existing code.
The Client now supports setting a maximum wait time before refreshing the token. This is useful for scenarios where you want to refresh the token before it expires, but not too often.
By default, GoTrue servers are typically set to expire the token after an hour, and the refresh thread will refresh the token when ~20% of that time is left.
However, you can set the expiration time to be much longer on the server (up to a week). In this scenario, you may want to refresh the token more often than once every 5 days or so, but not every hour.
There is now a new option MaximumRefreshWaitTime which allows you to specify the maximum amount
in time that the refresh thread will wait before refreshing the token. This defaults to 4 hours.
This means that if you have your server set to a one hour token expiration, nothing changes, but
if you extend the server refresh to (for example) a week, as long as the user launches the app
at least once a week, they will never have to re-authenticate.
GotrueException. A Reason field has been added
to GotrueException to clarify what happened. This should also be easier to manage as the Gotrue
server API & messages evolve.Save/Load/Destroy have been simplified to no longer require async.Client.AddDebugListener() and the test cases for examples.
This will allow you to implement your own logging strategy (write to temp file, console, user visible
err console, etc).Options headers.New feature:
Settings request to the stateless API only - you can now query the server instance to
determine if it's got the settings you need. This might allow for things like a visual
component in a tool to verify the GoTrue settings are working correctly, or tests that run differently
depending on the server configuration.Implementation notes:
ProviderAuthState rather
than a string.scopes into SignInOptionsIn Short:
# What was:
var url = await client.SignIn(Provider.Github, "scopes and things");
# Becomes:
var state = await client.SignIn(Provider.Github, new SignInOptions { "scopes and things" });
// Url is now at `state.Uri`
To use this library on the Supabase Hosted service but separately from the supabase-csharp, you'll need to specify
your url and public key like so:
var auth = new Supabase.Gotrue.Client(new ClientOptions<Session>
{
Url = "https://PROJECT_ID.supabase.co/auth/v1",
Headers = new Dictionary<string, string>
{
{ "apikey", SUPABASE_PUBLIC_KEY }
}
})
Otherwise, using it this library with a local instance:
var options = new ClientOptions { Url = "https://example.com/api" };
var client = new Client(options);
var user = await client.SignUp("new-user@example.com");
// Alternatively, you can use a StatelessClient and do API interactions that way
var options = new StatelessClientOptions { Url = "https://example.com/api" }
await new StatelessClient().SignUp("new-user@example.com", options);
This Gotrue client is written to be agnostic when it comes to session persistence, retrieval, and
destruction. ClientOptions exposes
properties that allow these to be specified.
In the event these are specified and the AutoRefreshToken option is set, as the Client Initializes, it will also
attempt to
retrieve, set, and refresh an existing session.
For example, using Xamarin.Essentials in Xamarin.Forms, this might look like:
// This is a method you add your application launch/setup
async void Initialize() {
// Specify the methods you'd like to use as persistence callbacks
var persistence = new GotrueSessionPersistence(SaveSession, LoadSession, DestroySession);
var client = new Client(
Url = GOTRUE_URL,
new ClientOptions {
AllowUnconfirmedUserSessions = true,
SessionPersistence = persistence });
// Specify a debug callback to listen to problems with the background token refresh thread
client.AddDebugListener(LogDebug);
// Specify a call back to listen to changes in the user state (logged in, out, etc)
client.AddStateChangedListener(AuthStateListener);
// Load the session from persistence
client.LoadSession();
// Loads the session using SessionRetriever and sets state internally.
await client.RetrieveSessionAsync();
}
// Add callback methods for above
// Here's a quick example of using this to save session data to the user's cache folder
// You'll want to add methods for loading the file and deleting when the user logs out
internal bool SaveSession(Session session)
{
var cacheFileName = ".gotrue.cache";
try
{
var cacheDir = FileSystem.CacheDirectory;
var path = Path.Join(cacheDir, cacheFileName);
var str = JsonConvert.SerializeObject(session);
using (StreamWriter file = new StreamWriter(path))
{
file.Write(str);
file.Dispose();
return Task.FromResult(true);
};
}
catch (Exception err)
{
Debug.WriteLine("Unable to write cache file.");
throw err;
}
}
Once again, Gotrue client is written to be agnostic of platform. In order for Gotrue to sign in a user from an Oauth callback, the PKCE flow is preferred:
client.SignIn(PROVIDER, options) and setting the options to use the
PKCE FlowTypeProviderAuthState.PKCEVerifier so that the application callback can use it to verify the returned codePKCEVerifier and received code to exchange for a session.var state = await client.SignIn(Constants.Provider.Github, new SignInOptions
{
FlowType = Constants.OAuthFlowType.PKCE,
RedirectTo = "http://localhost:3000/oauth/callback"
});
// In callback received from Supabase returning to RedirectTo (set above)
// Url is set as: http://REDIRECT_TO_URL?code=CODE
var session = await client.ExchangeCodeForSession(state.PKCEVerifier, RETRIEVE_CODE_FROM_GET_PARAMS);
Q: I've created a User but while attempting to log in it throws an exception:
A: Provided the credentials are correct, make sure that the User has also confirmed their email.
Adding a handler for email confirmation to a desktop or mobile application can be done, but it requires setting up URL handlers for each platform, which can be pretty difficult to do if you aren't really comfortable with configuring these handlers. ( e.g. Windows, Apple, Android) You may find it easier to create a simple web application to handle email confirmation - that way a user can just click a link in their email and get confirmed that way. Your desktop or mobile app should inspect the user object that comes back and use that to see if the user is confirmed.
You might find it easiest to do something like create and deploy a simple SvelteKit or even a very basic pure JavaScript project to handle email verification.
Join the ranks! See a problem? Help fix it!
<a href="https://github.com/supabase-community/gotrue-csharp/graphs/contributors"> <img src="https://contrib.rocks/image?repo=supabase-community/gotrue-csharp" /> </a>
<small>Made with contrib.rocks.</small>
We are more than happy to have contributions! Please submit a PR.
To run the tests locally you must have docker and docker-compose installed. Then in the root of the repository run:
docker-compose up -ddotnet test| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 1 NuGet packages that depend on gotrue-csharp:
| Package | Downloads |
|---|---|
|
supabase-csharp
A C# implementation of the Supabase client |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 4.3.1 | 3,540 | 4/5/2024 | 4.3.1 is deprecated. |
| 4.3.0 | 283 | 4/5/2024 | |
| 4.2.7 | 103,682 | 4/2/2024 | |
| 4.2.6 | 27,737 | 12/30/2023 | |
| 4.2.5 | 4,072 | 12/16/2023 | |
| 4.2.4 | 323 | 12/1/2023 | |
| 4.2.3 | 19,308 | 10/12/2023 | |
| 4.2.2 | 1,545 | 10/1/2023 | |
| 4.2.1 | 13,561 | 8/20/2023 | |
| 4.2.0 | 348 | 8/13/2023 | |
| 4.1.1 | 9,024 | 6/29/2023 | |
| 4.1.0 | 666 | 6/25/2023 | |
| 4.0.5 | 323 | 6/17/2023 | |
| 4.0.4 | 1,311 | 6/10/2023 | |
| 4.0.3 | 442 | 6/10/2023 | |
| 4.0.2 | 3,373 | 5/16/2023 | |
| 4.0.1 | 2,530 | 5/11/2023 | |
| 4.0.0 | 348 | 5/7/2023 | |
| 3.1.2 | 388 | 5/3/2023 | |
| 3.1.1 | 4,662 | 4/28/2023 |