Table of Contents

Interface IGotrueStatelessClient<TUser, TSession>

Namespace
Supabase.Gotrue.Interfaces
Assembly
Supabase.Gotrue.dll

A Stateless Gotrue Client

public interface IGotrueStatelessClient<TUser, TSession> where TUser : User where TSession : Session

Type Parameters

TUser
TSession

Examples

var options = new StatelessClientOptions { Url = "https://mygotrueurl.com" }; var user = await client.SignIn("user@email.com", "fancyPassword", options);

Methods

Challenge(string, MfaChallengeParams, StatelessClientOptions)

Prepares a challenge used to verify that a user has access to a MFA factor.

Task<MfaChallengeResponse?> Challenge(string jwt, MfaChallengeParams mfaChallengeParams, StatelessClient.StatelessClientOptions options)

Parameters

jwt string
mfaChallengeParams MfaChallengeParams
options StatelessClient.StatelessClientOptions

Returns

Task<MfaChallengeResponse>

ChallengeAndVerify(string, MfaChallengeAndVerifyParams, StatelessClientOptions)

Helper method which creates a challenge and immediately uses the given code to verify against it thereafter. The verification code is provided by the user by entering a code seen in their authenticator app.

Task<MfaVerifyResponse?> ChallengeAndVerify(string jwt, MfaChallengeAndVerifyParams mfaChallengeAndVerifyParams, StatelessClient.StatelessClientOptions options)

Parameters

jwt string
mfaChallengeAndVerifyParams MfaChallengeAndVerifyParams
options StatelessClient.StatelessClientOptions

Returns

Task<MfaVerifyResponse>

CreateUser(string, StatelessClientOptions, AdminUserAttributes)

Create a user

Task<TUser?> CreateUser(string serviceRoleToken, StatelessClient.StatelessClientOptions options, AdminUserAttributes attributes)

Parameters

serviceRoleToken string

A valid JWT. Must be a full-access API key (e.g. service_role key).

options StatelessClient.StatelessClientOptions
attributes AdminUserAttributes

Returns

Task<TUser>

CreateUser(string, StatelessClientOptions, string, string, AdminUserAttributes?)

Create a user

Task<TUser?> CreateUser(string serviceRoleToken, StatelessClient.StatelessClientOptions options, string email, string password, AdminUserAttributes? attributes = null)

Parameters

serviceRoleToken string

A valid JWT. Must be a full-access API key (e.g. service_role key).

options StatelessClient.StatelessClientOptions
email string
password string
attributes AdminUserAttributes

Returns

Task<TUser>

DeleteUser(string, string, StatelessClientOptions)

Deletes a User.

Task<bool> DeleteUser(string uid, string serviceRoleToken, StatelessClient.StatelessClientOptions options)

Parameters

uid string
serviceRoleToken string

this token needs role 'supabase_admin' or 'service_role'

options StatelessClient.StatelessClientOptions

Returns

Task<bool>

Enroll(string, MfaEnrollParams, StatelessClientOptions)

Starts the enrollment process for a new Multi-Factor Authentication (MFA) factor. This method creates a new unverified factor. To verify a factor, present the QR code or secret to the user and ask them to add it to their authenticator app. The user has to enter the code from their authenticator app to verify it.

Upon verifying a factor, all other sessions are logged out and the current session's authenticator level is promoted to aal2.

Task<MfaEnrollResponse?> Enroll(string jwt, MfaEnrollParams mfaEnrollParams, StatelessClient.StatelessClientOptions options)

Parameters

jwt string
mfaEnrollParams MfaEnrollParams
options StatelessClient.StatelessClientOptions

Returns

Task<MfaEnrollResponse>

ExchangeCodeForSession(string, string, StatelessClientOptions)

Logs in an existing user via a third-party provider.

Task<TSession?> ExchangeCodeForSession(string codeVerifier, string authCode, StatelessClient.StatelessClientOptions options)

Parameters

codeVerifier string
authCode string
options StatelessClient.StatelessClientOptions

Returns

Task<TSession>

GetApi(StatelessClientOptions)

Initialize/retrieve the underlying API for this client

IGotrueApi<TUser, TSession> GetApi(StatelessClient.StatelessClientOptions options)

Parameters

options StatelessClient.StatelessClientOptions

Returns

IGotrueApi<TUser, TSession>

GetAuthenticatorAssuranceLevel(string, StatelessClientOptions)

Returns the Authenticator Assurance Level (AAL) for the active session.

  • aal1 (or null) means that the user's identity has been verified only with a conventional login (email+password, OTP, magic link, social login, etc.).
  • aal2 means that the user's identity has been verified both with a conventional login and at least one MFA factor.

Although this method returns a promise, it's fairly quick (microseconds) and rarely uses the network. You can use this to check whether the current user needs to be shown a screen to verify their MFA factors.

Task<MfaGetAuthenticatorAssuranceLevelResponse?> GetAuthenticatorAssuranceLevel(string jwt, StatelessClient.StatelessClientOptions options)

Parameters

jwt string
options StatelessClient.StatelessClientOptions

Returns

Task<MfaGetAuthenticatorAssuranceLevelResponse>

GetSessionFromUrl(Uri, StatelessClientOptions)

Parses a Session out of a Uri's Query parameters.

Task<TSession?> GetSessionFromUrl(Uri uri, StatelessClient.StatelessClientOptions options)

Parameters

uri Uri
options StatelessClient.StatelessClientOptions

Returns

Task<TSession>

GetUser(string, StatelessClientOptions)

Get User details by JWT. Can be used to validate a JWT.

Task<TUser?> GetUser(string serviceRoleToken, StatelessClient.StatelessClientOptions options)

Parameters

serviceRoleToken string

A valid JWT. Must be a JWT that originates from a user.

options StatelessClient.StatelessClientOptions

Returns

Task<TUser>

GetUserById(string, StatelessClientOptions, string)

Get User details by Id

Task<TUser?> GetUserById(string serviceRoleToken, StatelessClient.StatelessClientOptions options, string userId)

Parameters

serviceRoleToken string

A valid JWT. Must be a full-access API key (e.g. service_role key).

options StatelessClient.StatelessClientOptions
userId string

Returns

Task<TUser>

InviteUserByEmail(string, string, StatelessClientOptions, InviteUserByEmailOptions?)

Sends an invite email link to the specified email.

Task<bool> InviteUserByEmail(string email, string serviceRoleToken, StatelessClient.StatelessClientOptions options, InviteUserByEmailOptions? inviteOptions = null)

Parameters

email string
serviceRoleToken string

this token needs role 'supabase_admin' or 'service_role'

options StatelessClient.StatelessClientOptions
inviteOptions InviteUserByEmailOptions

Returns

Task<bool>

ListFactors(string, StatelessClientOptions)

Returns the list of MFA factors enabled for this user

Task<MfaListFactorsResponse?> ListFactors(string jwt, StatelessClient.StatelessClientOptions options)

Parameters

jwt string
options StatelessClient.StatelessClientOptions

Returns

Task<MfaListFactorsResponse>

ListUsers(string, StatelessClientOptions, string?, string?, SortOrder, int?, int?)

Lists users

Task<UserList<User>?> ListUsers(string serviceRoleToken, StatelessClient.StatelessClientOptions options, string? filter = null, string? sortBy = null, Constants.SortOrder sortOrder = SortOrder.Descending, int? page = null, int? perPage = null)

Parameters

serviceRoleToken string

A valid JWT. Must be a full-access API key (e.g. service_role key).

options StatelessClient.StatelessClientOptions
filter string

A string for example part of the email

sortBy string

Snake case string of the given key, currently only created_at is supported

sortOrder Constants.SortOrder

asc or desc, if null desc is used

page int?

page to show for pagination

perPage int?

items per page for pagination

Returns

Task<UserList<User>>

RefreshToken(string, string, StatelessClientOptions)

Refreshes a Token

Task<TSession?> RefreshToken(string accessToken, string refreshToken, StatelessClient.StatelessClientOptions options)

Parameters

accessToken string
refreshToken string
options StatelessClient.StatelessClientOptions

Returns

Task<TSession>

ResetPasswordForEmail(string, StatelessClientOptions)

Sends a reset request to an email address.

Task<bool> ResetPasswordForEmail(string email, StatelessClient.StatelessClientOptions options)

Parameters

email string
options StatelessClient.StatelessClientOptions

Returns

Task<bool>

Exceptions

Exception

Sends a Magic email login link to the specified email.

Task<bool> SendMagicLink(string email, StatelessClient.StatelessClientOptions options, SignInOptions? signInOptions = null)

Parameters

email string
options StatelessClient.StatelessClientOptions
signInOptions SignInOptions

Returns

Task<bool>

Settings(StatelessClientOptions)

Retrieve the current settings for the Gotrue instance.

Task<Settings?> Settings(StatelessClient.StatelessClientOptions options)

Parameters

options StatelessClient.StatelessClientOptions

Returns

Task<Settings>

SignIn(Provider, StatelessClientOptions, SignInOptions?)

Retrieves a Url to redirect to for signing in with a Constants.Provider.

This method will need to be combined with GetSessionFromUrl(Uri, StatelessClientOptions) when the Application receives the Oauth Callback.

ProviderAuthState SignIn(Constants.Provider provider, StatelessClient.StatelessClientOptions options, SignInOptions? signInOptions = null)

Parameters

provider Constants.Provider
options StatelessClient.StatelessClientOptions
signInOptions SignInOptions

Returns

ProviderAuthState

Examples

var client = Supabase.Gotrue.Client.Initialize(options); var url = client.SignIn(Provider.Github);

// Do Redirect User

// Example code Application.HasReceivedOauth += async (uri) => { var session = await client.GetSessionFromUri(uri, true); }

SignIn(SignInType, string, string?, StatelessClientOptions?)

Log in an existing user, or login via a third-party provider.

Task<TSession?> SignIn(Constants.SignInType type, string identifierOrToken, string? password = null, StatelessClient.StatelessClientOptions? options = null)

Parameters

type Constants.SignInType

Type of Credentials being passed

identifierOrToken string

An email, phone, or RefreshToken

password string

Password to account (optional if RefreshToken)

options StatelessClient.StatelessClientOptions

Returns

Task<TSession>

SignIn(string, StatelessClientOptions, SignInOptions?)

Sends a Magic email login link to the specified email.

Task<bool> SignIn(string email, StatelessClient.StatelessClientOptions options, SignInOptions? signInOptions = null)

Parameters

email string
options StatelessClient.StatelessClientOptions
signInOptions SignInOptions

Returns

Task<bool>

SignIn(string, string, StatelessClientOptions)

Signs in a User with an email address and password.

Task<TSession?> SignIn(string email, string password, StatelessClient.StatelessClientOptions options)

Parameters

email string
password string
options StatelessClient.StatelessClientOptions

Returns

Task<TSession>

SignOut(string, StatelessClientOptions)

Logout a User This will revoke all refresh tokens for the user. JWT tokens will still be valid for stateless auth until they expire.

Task<bool> SignOut(string accessToken, StatelessClient.StatelessClientOptions options)

Parameters

accessToken string
options StatelessClient.StatelessClientOptions

Returns

Task<bool>

SignUp(SignUpType, string, string, StatelessClientOptions, SignUpOptions?)

Signs up a user

Task<TSession?> SignUp(Constants.SignUpType type, string identifier, string password, StatelessClient.StatelessClientOptions options, SignUpOptions? signUpOptions = null)

Parameters

type Constants.SignUpType

Type of signup

identifier string

Phone or Email

password string
options StatelessClient.StatelessClientOptions
signUpOptions SignUpOptions

Object containing redirectTo and optional user metadata (data)

Returns

Task<TSession>

SignUp(string, string, StatelessClientOptions, SignUpOptions?)

Signs up a user by email address

Task<TSession?> SignUp(string email, string password, StatelessClient.StatelessClientOptions options, SignUpOptions? signUpOptions = null)

Parameters

email string
password string
options StatelessClient.StatelessClientOptions
signUpOptions SignUpOptions

Object containing redirectTo and optional user metadata (data)

Returns

Task<TSession>

Unenroll(string, MfaUnenrollParams, StatelessClientOptions)

Unenroll removes a MFA factor. A user has to have an aal2 authenticator level in order to unenroll a verified factor.

Task<MfaUnenrollResponse?> Unenroll(string jwt, MfaUnenrollParams mfaUnenrollParams, StatelessClient.StatelessClientOptions options)

Parameters

jwt string
mfaUnenrollParams MfaUnenrollParams
options StatelessClient.StatelessClientOptions

Returns

Task<MfaUnenrollResponse>

Update(string, UserAttributes, StatelessClientOptions)

Updates a User's attributes

Task<TUser?> Update(string accessToken, UserAttributes attributes, StatelessClient.StatelessClientOptions options)

Parameters

accessToken string
attributes UserAttributes
options StatelessClient.StatelessClientOptions

Returns

Task<TUser>

UpdateUserById(string, StatelessClientOptions, string, AdminUserAttributes)

Update user by Id

Task<TUser?> UpdateUserById(string serviceRoleToken, StatelessClient.StatelessClientOptions options, string userId, AdminUserAttributes userData)

Parameters

serviceRoleToken string

A valid JWT. Must be a full-access API key (e.g. service_role key).

options StatelessClient.StatelessClientOptions
userId string
userData AdminUserAttributes

Returns

Task<TUser>

Verify(string, MfaVerifyParams, StatelessClientOptions)

Verifies a code against a challenge. The verification code is provided by the user by entering a code seen in their authenticator app.

Task<MfaVerifyResponse?> Verify(string jwt, MfaVerifyParams mfaVerifyParams, StatelessClient.StatelessClientOptions options)

Parameters

jwt string
mfaVerifyParams MfaVerifyParams
options StatelessClient.StatelessClientOptions

Returns

Task<MfaVerifyResponse>

VerifyOTP(string, string, StatelessClientOptions, EmailOtpType)

Log in a user give a user supplied OTP received via email.

Task<TSession?> VerifyOTP(string email, string otpToken, StatelessClient.StatelessClientOptions options, Constants.EmailOtpType type = EmailOtpType.MagicLink)

Parameters

email string
otpToken string
options StatelessClient.StatelessClientOptions
type Constants.EmailOtpType

Returns

Task<TSession>

VerifyOTP(string, string, StatelessClientOptions, MobileOtpType)

Log in a user given a User supplied OTP received via mobile.

Task<TSession?> VerifyOTP(string phone, string otpToken, StatelessClient.StatelessClientOptions options, Constants.MobileOtpType type = MobileOtpType.SMS)

Parameters

phone string

The user's phone number.

otpToken string

Token sent to the user's phone.

options StatelessClient.StatelessClientOptions
type Constants.MobileOtpType

Returns

Task<TSession>

VerifyTokenHash(string, StatelessClientOptions, EmailOtpType)

Log in a user given the token hash used in an email confirmation link.

Task<TSession?> VerifyTokenHash(string tokenHash, StatelessClient.StatelessClientOptions options, Constants.EmailOtpType type = EmailOtpType.Email)

Parameters

tokenHash string
options StatelessClient.StatelessClientOptions
type Constants.EmailOtpType

Returns

Task<TSession>