Giter Site home page Giter Site logo

misterjimson / gotrue-csharp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from supabase-community/gotrue-csharp

0.0 2.0 0.0 1.17 MB

C# implementation of Supabase's GoTrue

Home Page: https://supabase-community.github.io/gotrue-csharp/api/Supabase.Gotrue.Client.html

License: MIT License

C# 97.05% PLpgSQL 2.95%

gotrue-csharp's Introduction


Getting Started

The Gotrue Client from this library uses a Singleton class to maintain in-memory state and timers. This is similar to the method that Firebase uses in its Client libraries. It can maintain sessions, refresh tokens, persistence, etc. for the developer, rather than having to do that yourself.

Alternatively, a StatelessClient is also provided within this library that allows interactions directly with the API without requiring initialization.

var options = new ClientOptions { Url = "https://example.com/api" };
var client = await Client.Initialize(options);

var user = await SignUp("[email protected]");

// Alternatively, you can use a StatelessClient and do API interactions that way
var options = new StatelessClientOptions { Url = "https://example.com/api" }
await Client.SignUp("[email protected]", options);

Persisting, Retrieving, and Destroying Sessions.

This Gotrue client is written to be agnostic when it comes to session persistance, 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:

var cacheFileName = ".gotrue.cache";

async void Initialize() {
    var options = new ClientOptions
    {
        Url = GOTRUE_URL,
        SessionPersistor = SessionPersistor,
        SessionRetriever = SessionRetriever,
        SessionDestroyer = SessionDestroyer
    };
    await Client.Initialize(options);
}

//...

internal Task<bool> SessionPersistor(Session session)
{
    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;
    }
}

3rd Party Authentication and Callbacks.

Once again, Gotrue client is written to be agnostic of platform. In order for Gotrue to sign in a user from an Oauth callback:

  1. The Callback Url must be set in the Supabase Admin panel
  2. The Application should recieve that Callback
  3. In the Callback, the Uri should be passed to Client.Instance.GetSessionFromUrl(uri)

Setting the second parameter of GetSessionFromUrl to false will prevent the storage of the parsed Session object.

Troubleshooting

I've created a User but while attempting to log in it throws an exception:

Provided the credentials are correct, make sure that the User has also confirmed their email.

Status

  • API
    • Sign Up with Email
    • Sign In with Email
    • Send Magic Link Email
    • Invite User by Email
    • Reset Password for Email
    • Signout
    • Get Url for Provider
    • Get User
    • Update User
    • Refresh Access Token
    • List Users (includes filtering, sorting, pagination)
    • Get User by Id
    • Create User
    • Update User by Id
  • Client
    • Get User
    • Refresh Session
    • Auth State Change Handler
    • Provider Sign In (Provides URL)
  • Provide Interfaces for Custom Token Persistence Functionality
  • Documentation
  • Unit Tests
  • Nuget Release

Package made possible through the efforts of:

Join the ranks! See a problem? Help fix it!

Made with contrib.rocks.

Contributing

We are more than happy to have contributions! Please submit a PR.

gotrue-csharp's People

Contributors

acupofjose avatar phxtho avatar elrhomariyounes avatar harryet avatar fplaras avatar theonlybeardedbeast avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.