Class Api
The REST calls to the Gotrue API.
public class Api : IGotrueApi<User, Session>, IGettableHeaders
- Inheritance
-
Api
- Implements
-
IGettableHeaders
- Inherited Members
Constructors
Api(string, Dictionary<string, string>?)
Creates a new API client
public Api(string url, Dictionary<string, string>? headers = null)
Parameters
url
stringheaders
Dictionary<string, string>
Properties
GetHeaders
Function that can be set to return dynamic headers. Headers specified in the constructor will ALWAYS take precedence over headers returned by this function.
public Func<Dictionary<string, string>>? GetHeaders { get; set; }
Property Value
Headers
Headers to be sent with every request. These will be merged with any headers returned by GetHeaders.
protected Dictionary<string, string> Headers { get; set; }
Property Value
Methods
Challenge(string, MfaChallengeParams)
public Task<MfaChallengeResponse?> Challenge(string jwt, MfaChallengeParams mfaChallengeParams)
Parameters
jwt
stringmfaChallengeParams
MfaChallengeParams
Returns
CreateUser(string, AdminUserAttributes?)
Create a user
public Task<User?> CreateUser(string jwt, AdminUserAttributes? attributes = null)
Parameters
jwt
stringA valid JWT. Must be a full-access API key (e.g. service_role key).
attributes
AdminUserAttributesAdditional administrative details
Returns
DeleteFactor(string, MfaAdminDeleteFactorParams)
public Task<MfaAdminDeleteFactorResponse?> DeleteFactor(string jwt, MfaAdminDeleteFactorParams deleteFactorParams)
Parameters
jwt
stringdeleteFactorParams
MfaAdminDeleteFactorParams
Returns
DeleteUser(string, string)
Delete a user
public Task<BaseResponse> DeleteUser(string uid, string jwt)
Parameters
uid
stringThe user uid you want to remove.
jwt
stringA valid JWT. Must be a full-access API key (e.g. service_role key).
Returns
Enroll(string, MfaEnrollParams)
public Task<MfaEnrollResponse?> Enroll(string jwt, MfaEnrollParams mfaEnrollParams)
Parameters
jwt
stringmfaEnrollParams
MfaEnrollParams
Returns
ExchangeCodeForSession(string, string)
Log in an existing user via code from third-party provider.
public Task<Session?> ExchangeCodeForSession(string codeVerifier, string authCode)
Parameters
codeVerifier
stringGenerated verifier (probably from GetUrlForProvider)
authCode
stringThe received Auth Code Callback
Returns
GenerateLink(string, GenerateLinkOptions)
Generates email links and OTPs to be sent via a custom email provider.
public Task<BaseResponse> GenerateLink(string jwt, GenerateLinkOptions options)
Parameters
jwt
stringoptions
GenerateLinkOptions
Returns
GetUriForProvider(Provider, SignInOptions?)
public ProviderAuthState GetUriForProvider(Constants.Provider provider, SignInOptions? options = null)
Parameters
provider
Constants.Provideroptions
SignInOptions
Returns
GetUser(string)
Gets User Details
public Task<User?> GetUser(string jwt)
Parameters
jwt
string
Returns
GetUserById(string, string)
Get User details by Id
public Task<User?> GetUserById(string jwt, string userId)
Parameters
Returns
InviteUserByEmail(string, string, InviteUserByEmailOptions?)
Sends an invite link to an email address.
public Task<BaseResponse> InviteUserByEmail(string email, string jwt, InviteUserByEmailOptions? options = null)
Parameters
email
stringjwt
stringthis token needs role 'supabase_admin' or 'service_role'
options
InviteUserByEmailOptions
Returns
LinkIdentity(string, Provider, SignInOptions)
Links an oauth identity to an existing user.
This method requires the PKCE flow.
public Task<ProviderAuthState> LinkIdentity(string token, Constants.Provider provider, SignInOptions options)
Parameters
token
stringUser's token
provider
Constants.ProviderProvider to Link
options
SignInOptions
Returns
ListFactors(string, MfaAdminListFactorsParams)
public Task<BaseResponse> ListFactors(string jwt, MfaAdminListFactorsParams listFactorsParams)
Parameters
jwt
stringlistFactorsParams
MfaAdminListFactorsParams
Returns
ListUsers(string, string?, string?, SortOrder, int?, int?)
Lists users
public Task<UserList<User>?> ListUsers(string jwt, string? filter = null, string? sortBy = null, Constants.SortOrder sortOrder = SortOrder.Descending, int? page = null, int? perPage = null)
Parameters
jwt
stringA valid JWT. Must be a full-access API key (e.g. service_role key).
filter
stringA string for example part of the email
sortBy
stringSnake case string of the given key, currently only created_at is supported
sortOrder
Constants.SortOrderasc or desc, if null desc is used
page
int?page to show for pagination
perPage
int?items per page for pagination
Returns
Reauthenticate(string)
Sends a re-authentication request, used for password changes.
public Task<BaseResponse> Reauthenticate(string userJwt)
Parameters
userJwt
stringThe user's auth token.
Returns
RefreshAccessToken(string, string)
Generates a new Session given a user's access token and refresh token.
public Task<Session?> RefreshAccessToken(string accessToken, string refreshToken)
Parameters
Returns
ResetPasswordForEmail(ResetPasswordForEmailOptions)
Sends a password reset request to an email address.
This Method supports the PKCE Flow
public Task<ResetPasswordForEmailState> ResetPasswordForEmail(ResetPasswordForEmailOptions options)
Parameters
options
ResetPasswordForEmailOptions
Returns
ResetPasswordForEmail(string)
Sends a reset request to an email address.
public Task<BaseResponse> ResetPasswordForEmail(string email)
Parameters
email
string
Returns
SendMagicLinkEmail(string, SignInOptions?)
Sends a magic login link to an email address.
public Task<BaseResponse> SendMagicLinkEmail(string email, SignInOptions? options = null)
Parameters
email
stringoptions
SignInOptions
Returns
SendMobileOTP(string)
Sends a mobile OTP via SMS. Will register the account if it doesn't already exist
public Task<BaseResponse> SendMobileOTP(string phone)
Parameters
phone
stringphone The user's phone number WITH international prefix
Returns
Settings()
Calls the GoTrue server to get the settings (for example, if email auto confirmation is turned on)
public Task<Settings?> Settings()
Returns
SignInAnonymously(SignInAnonymouslyOptions?)
Creates a new anonymous user.
public Task<Session?> SignInAnonymously(SignInAnonymouslyOptions? options = null)
Parameters
options
SignInAnonymouslyOptions
Returns
SignInWithEmail(string, string)
Logs in an existing user using their email address.
public Task<Session?> SignInWithEmail(string email, string password)
Parameters
Returns
SignInWithIdToken(Provider, string, string?, string?, string?)
Allows signing in with an ID token issued by certain supported providers. The [idToken] is verified for validity and a new session is established. This method of signing in only supports [Provider.Google] or [Provider.Apple].
public Task<Session?> SignInWithIdToken(Constants.Provider provider, string idToken, string? accessToken = null, string? nonce = null, string? captchaToken = null)
Parameters
provider
Constants.ProviderA supported provider (Google, Apple, Azure, Facebook)
idToken
stringOIDC ID token issued by the specified provider. The
iss
claim in the ID token must match the supplied provider. Some ID tokens contain anat_hash
which require that you provide anaccess_token
value to be accepted properly. If the token contains anonce
claim you must supply the nonce used to obtain the ID token.accessToken
stringIf the ID token contains an
at_hash
claim, then the hash of this value is compared to the value in the ID token.nonce
stringIf the ID token contains a
nonce
claim, then the hash of this value is compared to the value in the ID token.captchaToken
stringVerification token received when the user completes the captcha on the site.
Returns
SignInWithOtp(SignInWithPasswordlessEmailOptions)
Log in a user using magiclink or a one-time password (OTP).
If the {{ .ConfirmationURL }}
variable is specified in the email template, a magiclink will be sent.
If the {{ .Token }}
variable is specified in the email template, an OTP will be sent.
If you're using phone sign-ins, only an OTP will be sent. You won't be able to send a magiclink for phone sign-ins.
Be aware that you may get back an error message that will not distinguish between the cases where the account does not exist or, that the account can only be accessed via social login.
Do note that you will need to configure a Whatsapp sender on Twilio if you are using phone sign in with the 'whatsapp' channel. The whatsapp channel is not supported on other providers at this time.
public Task<PasswordlessSignInState> SignInWithOtp(SignInWithPasswordlessEmailOptions options)
Parameters
Returns
SignInWithOtp(SignInWithPasswordlessPhoneOptions)
Log in a user using magiclink or a one-time password (OTP).
If the {{ .ConfirmationURL }}
variable is specified in the email template, a magiclink will be sent.
If the {{ .Token }}
variable is specified in the email template, an OTP will be sent.
If you're using phone sign-ins, only an OTP will be sent. You won't be able to send a magiclink for phone sign-ins.
Be aware that you may get back an error message that will not distinguish between the cases where the account does not exist or, that the account can only be accessed via social login.
Do note that you will need to configure a Whatsapp sender on Twilio if you are using phone sign in with the 'whatsapp' channel. The whatsapp channel is not supported on other providers at this time.
public Task<PasswordlessSignInState> SignInWithOtp(SignInWithPasswordlessPhoneOptions options)
Parameters
Returns
SignInWithPhone(string, string)
Logs in an existing user using their phone number and password.
public Task<Session?> SignInWithPhone(string phone, string password)
Parameters
Returns
SignInWithSSO(Guid, SignInWithSSOOptions?)
public Task<SSOResponse?> SignInWithSSO(Guid providerId, SignInWithSSOOptions? options = null)
Parameters
providerId
Guidoptions
SignInWithSSOOptions
Returns
SignInWithSSO(string, SignInWithSSOOptions?)
public Task<SSOResponse?> SignInWithSSO(string domain, SignInWithSSOOptions? options = null)
Parameters
domain
stringoptions
SignInWithSSOOptions
Returns
SignOut(string, SignOutScope)
Removes a logged-in session.
public Task<BaseResponse> SignOut(string jwt, Constants.SignOutScope scope = SignOutScope.Global)
Parameters
jwt
stringscope
Constants.SignOutScope
Returns
SignUpWithEmail(string, string, SignUpOptions?)
Signs a user up using an email address and password.
public Task<Session?> SignUpWithEmail(string email, string password, SignUpOptions? options = null)
Parameters
email
stringpassword
stringoptions
SignUpOptionsOptional Signup data.
Returns
SignUpWithPhone(string, string, SignUpOptions?)
Signs up a new user using their phone number and a password.The phone number of the user.
public Task<Session?> SignUpWithPhone(string phone, string password, SignUpOptions? options = null)
Parameters
phone
stringThe phone number of the user.
password
stringThe password of the user.
options
SignUpOptionsOptional Signup data.
Returns
Unenroll(string, MfaUnenrollParams)
public Task<MfaUnenrollResponse?> Unenroll(string jwt, MfaUnenrollParams mfaUnenrollParams)
Parameters
jwt
stringmfaUnenrollParams
MfaUnenrollParams
Returns
UnlinkIdentity(string, UserIdentity)
Unlinks an identity from a user by deleting it. The user will no longer be able to sign in with that identity once it's unlinked.
public Task<bool> UnlinkIdentity(string token, UserIdentity userIdentity)
Parameters
token
stringUser's token
userIdentity
UserIdentityIdentity to be unlinked
Returns
UpdateUser(string, UserAttributes)
Updates the User data
public Task<User?> UpdateUser(string jwt, UserAttributes attributes)
Parameters
jwt
stringattributes
UserAttributes
Returns
UpdateUserById(string, string, UserAttributes)
Update user by Id
public Task<User?> UpdateUserById(string jwt, string userId, UserAttributes userData)
Parameters
jwt
stringA valid JWT. Must be a full-access API key (e.g. service_role key).
userId
stringuserID
userData
UserAttributesUser attributes e.g. email, password, etc.
Returns
Verify(string, MfaVerifyParams)
public Task<MfaVerifyResponse?> Verify(string jwt, MfaVerifyParams mfaVerifyParams)
Parameters
jwt
stringmfaVerifyParams
MfaVerifyParams
Returns
VerifyEmailOTP(string, string, EmailOtpType)
Send User supplied Email OTP to be verified
public Task<Session?> VerifyEmailOTP(string email, string token, Constants.EmailOtpType type)
Parameters
email
stringThe user's email address
token
stringtoken that user was sent to their mobile phone
type
Constants.EmailOtpTypeType of verification, e.g. invite, recovery, etc.
Returns
VerifyMobileOTP(string, string, MobileOtpType)
Send User supplied Mobile OTP to be verified
public Task<Session?> VerifyMobileOTP(string phone, string token, Constants.MobileOtpType type)
Parameters
phone
stringThe user's phone number WITH international prefix
token
stringtoken that user was sent to their mobile phone
type
Constants.MobileOtpTypee.g. SMS or phone change
Returns
VerifyTokenHash(string, EmailOtpType)
Verify token hash used in an email confirmation link.
public Task<Session?> VerifyTokenHash(string tokenHash, Constants.EmailOtpType type)
Parameters
tokenHash
stringThe token hash used in an email confirmation link
type
Constants.EmailOtpTypeType of verification, e.g. email.