Class Api
The REST calls to the Gotrue API.
public class Api : IGotrueApi<User, Session>, IGettableHeaders
- Inheritance
-
Api
- Implements
- Inherited Members
Constructors
Api(string, Dictionary<string, string>?)
Creates a new API client
public Api(string url, Dictionary<string, string>? headers = null)
Parameters
urlstringheadersDictionary<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
jwtstringmfaChallengeParamsMfaChallengeParams
Returns
CreateUser(string, AdminUserAttributes?)
Create a user
public Task<User?> CreateUser(string jwt, AdminUserAttributes? attributes = null)
Parameters
jwtstringA valid JWT. Must be a full-access API key (e.g. service_role key).
attributesAdminUserAttributesAdditional administrative details
Returns
DeleteFactor(string, MfaAdminDeleteFactorParams)
public Task<MfaAdminDeleteFactorResponse?> DeleteFactor(string jwt, MfaAdminDeleteFactorParams deleteFactorParams)
Parameters
jwtstringdeleteFactorParamsMfaAdminDeleteFactorParams
Returns
DeleteUser(string, string)
Delete a user
public Task<BaseResponse> DeleteUser(string uid, string jwt)
Parameters
uidstringThe user uid you want to remove.
jwtstringA 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
jwtstringmfaEnrollParamsMfaEnrollParams
Returns
ExchangeCodeForSession(string, string)
Log in an existing user via code from third-party provider.
public Task<Session?> ExchangeCodeForSession(string codeVerifier, string authCode)
Parameters
codeVerifierstringGenerated verifier (probably from GetUrlForProvider)
authCodestringThe 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
jwtstringoptionsGenerateLinkOptions
Returns
GetUriForProvider(Provider, SignInOptions?)
public ProviderAuthState GetUriForProvider(Constants.Provider provider, SignInOptions? options = null)
Parameters
providerConstants.ProvideroptionsSignInOptions
Returns
GetUser(string)
Gets User Details
public Task<User?> GetUser(string jwt)
Parameters
jwtstring
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
emailstringjwtstringthis token needs role 'supabase_admin' or 'service_role'
optionsInviteUserByEmailOptions
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
tokenstringUser's token
providerConstants.ProviderProvider to Link
optionsSignInOptions
Returns
ListFactors(string, MfaAdminListFactorsParams)
public Task<BaseResponse> ListFactors(string jwt, MfaAdminListFactorsParams listFactorsParams)
Parameters
jwtstringlistFactorsParamsMfaAdminListFactorsParams
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
jwtstringA valid JWT. Must be a full-access API key (e.g. service_role key).
filterstringA string for example part of the email
sortBystringSnake case string of the given key, currently only created_at is supported
sortOrderConstants.SortOrderasc or desc, if null desc is used
pageint?page to show for pagination
perPageint?items per page for pagination
Returns
Reauthenticate(string)
Sends a re-authentication request, used for password changes.
public Task<BaseResponse> Reauthenticate(string userJwt)
Parameters
userJwtstringThe 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
optionsResetPasswordForEmailOptions
Returns
ResetPasswordForEmail(string)
Sends a reset request to an email address.
public Task<BaseResponse> ResetPasswordForEmail(string email)
Parameters
emailstring
Returns
SendMagicLinkEmail(string, SignInOptions?)
Sends a magic login link to an email address.
public Task<BaseResponse> SendMagicLinkEmail(string email, SignInOptions? options = null)
Parameters
emailstringoptionsSignInOptions
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
phonestringphone 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
optionsSignInAnonymouslyOptions
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
providerConstants.ProviderA supported provider (Google, Apple, Azure, Facebook)
idTokenstringOIDC ID token issued by the specified provider. The
issclaim in the ID token must match the supplied provider. Some ID tokens contain anat_hashwhich require that you provide anaccess_tokenvalue to be accepted properly. If the token contains anonceclaim you must supply the nonce used to obtain the ID token.accessTokenstringIf the ID token contains an
at_hashclaim, then the hash of this value is compared to the value in the ID token.noncestringIf the ID token contains a
nonceclaim, then the hash of this value is compared to the value in the ID token.captchaTokenstringVerification 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
providerIdGuidoptionsSignInWithSSOOptions
Returns
SignInWithSSO(string, SignInWithSSOOptions?)
public Task<SSOResponse?> SignInWithSSO(string domain, SignInWithSSOOptions? options = null)
Parameters
domainstringoptionsSignInWithSSOOptions
Returns
SignOut(string, SignOutScope)
Removes a logged-in session.
public Task<BaseResponse> SignOut(string jwt, Constants.SignOutScope scope = SignOutScope.Global)
Parameters
jwtstringscopeConstants.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
emailstringpasswordstringoptionsSignUpOptionsOptional 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
phonestringThe phone number of the user.
passwordstringThe password of the user.
optionsSignUpOptionsOptional Signup data.
Returns
Unenroll(string, MfaUnenrollParams)
public Task<MfaUnenrollResponse?> Unenroll(string jwt, MfaUnenrollParams mfaUnenrollParams)
Parameters
jwtstringmfaUnenrollParamsMfaUnenrollParams
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
tokenstringUser's token
userIdentityUserIdentityIdentity to be unlinked
Returns
UpdateUser(string, UserAttributes)
Updates the User data
public Task<User?> UpdateUser(string jwt, UserAttributes attributes)
Parameters
jwtstringattributesUserAttributes
Returns
UpdateUserById(string, string, UserAttributes)
Update user by Id
public Task<User?> UpdateUserById(string jwt, string userId, UserAttributes userData)
Parameters
jwtstringA valid JWT. Must be a full-access API key (e.g. service_role key).
userIdstringuserID
userDataUserAttributesUser attributes e.g. email, password, etc.
Returns
Verify(string, MfaVerifyParams)
public Task<MfaVerifyResponse?> Verify(string jwt, MfaVerifyParams mfaVerifyParams)
Parameters
jwtstringmfaVerifyParamsMfaVerifyParams
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
emailstringThe user's email address
tokenstringtoken that user was sent to their mobile phone
typeConstants.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
phonestringThe user's phone number WITH international prefix
tokenstringtoken that user was sent to their mobile phone
typeConstants.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
tokenHashstringThe token hash used in an email confirmation link
typeConstants.EmailOtpTypeType of verification, e.g. email.