Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor exceptions, code cleanup, and move to delegate auth state changes #57

Merged
merged 75 commits into from
May 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
cac2961
Add GoTrue specific words to dictionary
wiverson May 4, 2023
73e3a3e
Minor cleanup.
wiverson May 4, 2023
c1d54e5
Minor cleanup.
wiverson May 4, 2023
25d698c
Remove unneeded declarations
wiverson May 4, 2023
e72c649
Remove unused imports.
wiverson May 4, 2023
71dea23
Simplify imports
wiverson May 4, 2023
a04feb9
Remove unused imports
wiverson May 4, 2023
6fb6376
Remove unused imports
wiverson May 4, 2023
4191d97
Remove unused imports
wiverson May 4, 2023
484fd4b
Remove unused imports
wiverson May 4, 2023
3abb4e6
Remove unused imports
wiverson May 4, 2023
e54ec16
Remove unused imports
wiverson May 4, 2023
fa22019
Remove unused import
wiverson May 4, 2023
07291ea
Remove unused import
wiverson May 4, 2023
5f6497c
Removed unused imports.
wiverson May 4, 2023
4ed3faa
Simplify imports
wiverson May 4, 2023
5e56caf
Simplify imports
wiverson May 4, 2023
db1e73c
Simplify imports
wiverson May 4, 2023
59362e5
Fix doc
wiverson May 4, 2023
14b990b
Simplify imports, fix doc
wiverson May 4, 2023
e26eeb8
Simplify imports, doc fixes
wiverson May 4, 2023
a1e4821
Add bit more coverage for nonce tests
wiverson May 4, 2023
6b002a2
Import code formatting rules from existing code base
wiverson May 4, 2023
c987e7e
Remove debug. Fix floating point warning.
wiverson May 4, 2023
2a5302f
Remove debug.
wiverson May 4, 2023
84b0698
Replace debug. Also ran code format on existing rules.
wiverson May 4, 2023
38563b8
Simplify exceptions, persistence, state changes
wiverson May 5, 2023
643382c
Updates/fixes for persistence and notifications
wiverson May 5, 2023
6fa91f8
Simplify exceptions
wiverson May 5, 2023
103e6ab
Add failure test cases. Split anon and service tests
wiverson May 5, 2023
4052ec3
Remove unneeded imports
wiverson May 5, 2023
1cb9d30
Add abbreviations to spelling check
wiverson May 5, 2023
acdbe26
Make consistent with rest of project code style
wiverson May 5, 2023
80c0e08
Changed to use Options headers as sole source of truth
wiverson May 5, 2023
7eb9b55
Create ConfigurationFailureTests.cs
wiverson May 5, 2023
da6be92
Remove readonly
wiverson May 5, 2023
58bb4a4
Remove client launch
wiverson May 5, 2023
e34671c
Add bearer token failure
wiverson May 5, 2023
d056827
Comment out debug (used to match server errors)
wiverson May 5, 2023
0c8f5ab
Remove client launch
wiverson May 5, 2023
665b6c3
Remove unused empty default headers
wiverson May 5, 2023
d64f9ed
Remove imports
wiverson May 5, 2023
a1ad500
Add load user from persistence test
wiverson May 5, 2023
7770aae
simplify with static import
wiverson May 5, 2023
617413f
format
wiverson May 5, 2023
6685b5a
Add info on changes
wiverson May 5, 2023
e7d8a96
Remove imports
wiverson May 5, 2023
9eec8b7
Doc fix
wiverson May 5, 2023
048fd82
Add doc
wiverson May 5, 2023
aaaea3a
Add doc
wiverson May 5, 2023
6fccd8f
Merge remote-tracking branch 'upstream/master' into refactor_exceptions
wiverson May 5, 2023
370f04b
Reformatted, added a few more words to spell checker
wiverson May 5, 2023
46da91d
Add settings endpoint
wiverson May 5, 2023
8516460
Minor method changes. Added some docs.
wiverson May 5, 2023
9320674
Simplified to holder class
wiverson May 5, 2023
6db9ff4
Added User hint to clarify user needs to fix
wiverson May 5, 2023
80f21ba
Minor method renames, changed magic link back to sign in
wiverson May 5, 2023
be3c498
Session wrapper object
wiverson May 5, 2023
c820ab4
reformat
wiverson May 5, 2023
3f46a60
Simplified/tweaked to use persistence object
wiverson May 5, 2023
5722fd4
Settings object JSON wrapper
wiverson May 5, 2023
5f71925
Add settings API request
wiverson May 5, 2023
c66e371
Update Reason name, moved test to failure test
wiverson May 5, 2023
dd9da1a
Changes to tests per other changes
wiverson May 5, 2023
0a8df1c
Add settings api test case
wiverson May 5, 2023
85f5cb8
Update README to reflect changes
wiverson May 5, 2023
3c8d69d
Add note about settings api
wiverson May 5, 2023
1da3f2a
Add internal to set
wiverson May 5, 2023
9c8abc2
Cleanup methods that are essentially aliasing `Api` calls.
acupofjose May 6, 2023
3269047
Add code highlights
acupofjose May 6, 2023
6a297ee
Update gotrue-csharp.sln.DotSettings
wiverson May 6, 2023
5d89a16
Simplify session persistence with interface
wiverson May 6, 2023
6f7e899
Move setting persistence to method instead of options
wiverson May 6, 2023
0dcdb51
Extract interface for `PersistenceListener`
acupofjose May 7, 2023
63470d2
Update `IGotrueClient` interface for Persistence
acupofjose May 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 22 additions & 24 deletions Gotrue/Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ namespace Supabase.Gotrue
{
public class Api : IGotrueApi<User, Session>
{
protected string Url { get; private set; }
private string Url { get; }

/// <summary>
/// Function that can be set to return dynamic headers.
///
/// Headers specified in the constructor will ALWAYS take precedence over headers returned by this function.
/// </summary>
public Func<Dictionary<string, string>>? GetHeaders { get; set; }
Expand All @@ -39,14 +38,13 @@ protected Dictionary<string, string> Headers
}

/// <summary>
/// Creates a new user using their email address.
/// Creates a new API client
/// </summary>
/// <param name="url"></param>
/// <param name="headers"></param>
public Api(string url, Dictionary<string, string>? headers = null)
{
Url = url;

headers ??= new Dictionary<string, string>();
_headers = headers;
}
Expand All @@ -61,8 +59,7 @@ public Api(string url, Dictionary<string, string>? headers = null)
public async Task<Session?> SignUpWithEmail(string email, string password, SignUpOptions? options = null)
{
var body = new Dictionary<string, object> { { "email", email }, { "password", password } };

string endpoint = $"{Url}/signup";
var endpoint = $"{Url}/signup";

if (options != null)
{
Expand Down Expand Up @@ -94,10 +91,7 @@ public Api(string url, Dictionary<string, string>? headers = null)

return session;
}
else
{
return null;
}
return null;
}

/// <summary>
Expand Down Expand Up @@ -138,12 +132,12 @@ public async Task<PasswordlessSignInState> SignInWithOtp(SignInWithPasswordlessE
{
{ "email", options.Email },
{ "data", options.Data },
{ "create_user", options.ShouldCreateUser },
{ "create_user", options.ShouldCreateUser }
};

if (options.FlowType == OAuthFlowType.PKCE)
{
string challenge = Helpers.GenerateNonce();
var challenge = Helpers.GenerateNonce();
verifier = Helpers.GeneratePKCENonceVerifier(challenge);

body.Add("code_challenge", challenge);
Expand Down Expand Up @@ -205,16 +199,18 @@ public async Task<PasswordlessSignInState> SignInWithOtp(SignInWithPasswordlessP
/// <param name="nonce"></param>
/// <param name="captchaToken"></param>
/// <returns></returns>
/// <exception cref="InvalidProviderException"></exception>
/// <exception>
/// <cref>InvalidProviderException</cref>
/// </exception>
public Task<Session?> SignInWithIdToken(Provider provider, string idToken, string? nonce = null, string? captchaToken = null)
{
if (provider != Provider.Google && provider != Provider.Apple)
throw new InvalidProviderException($"Provider must either be: `Provider.Google` or `Provider.Apple`.");
throw new GotrueException($"Provider must be `Provider.Google` or `Provider.Apple` not {provider}");

var body = new Dictionary<string, object?>
{
{"provider", Core.Helpers.GetMappedToAttr(provider).Mapping },
{"id_token", idToken },
{"id_token", idToken }
};

if (!string.IsNullOrEmpty(nonce))
Expand All @@ -237,7 +233,7 @@ public Task<BaseResponse> SendMagicLinkEmail(string email, SignInOptions? option
{
var data = new Dictionary<string, string> { { "email", email } };

string endpoint = $"{Url}/magiclink";
var endpoint = $"{Url}/magiclink";

if (options != null)
{
Expand Down Expand Up @@ -304,7 +300,7 @@ public Task<BaseResponse> InviteUserByEmail(string email, string jwt)
{
var data = new Dictionary<string, object> {
{ "phone", phone },
{ "password", password },
{ "password", password }
};
return Helpers.MakeRequest<Session>(HttpMethod.Post, $"{Url}/token?grant_type=password", data, Headers);
}
Expand Down Expand Up @@ -406,9 +402,9 @@ public ProviderAuthState GetUriForProvider(Provider provider, SignInOptions? opt
result.PKCEVerifier = codeVerifier;
}

if (attr is MapToAttribute mappedAttr)
if (attr is MapToAttribute)
{
query.Add("provider", mappedAttr.Mapping);
query.Add("provider", attr.Mapping);

if (!string.IsNullOrEmpty(options.Scopes))
query.Add("scopes", options.Scopes);
Expand Down Expand Up @@ -500,7 +496,7 @@ public Task<BaseResponse> SignOut(string jwt)
/// </summary>
/// <param name="jwt">A valid JWT. Must be a full-access API key (e.g. service_role key).</param>
/// <param name="filter">A string for example part of the email</param>
/// <param name="sortBy">Snake case string of the given key, currently only created_at is suppported</param>
/// <param name="sortBy">Snake case string of the given key, currently only created_at is supported</param>
/// <param name="sortOrder">asc or desc, if null desc is used</param>
/// <param name="page">page to show for pagination</param>
/// <param name="perPage">items per page for pagination</param>
Expand Down Expand Up @@ -548,10 +544,7 @@ private Dictionary<string, string> TransformListUsersParams(string? filter = nul
/// <returns></returns>
public Task<User?> CreateUser(string jwt, AdminUserAttributes? attributes = null)
{
if (attributes == null)
{
attributes = new AdminUserAttributes();
}
attributes ??= new AdminUserAttributes();

return Helpers.MakeRequest<User>(HttpMethod.Post, $"{Url}/admin/users", attributes, CreateAuthedRequestHeaders(jwt));
}
Expand Down Expand Up @@ -580,6 +573,11 @@ public Task<BaseResponse> DeleteUser(string uid, string jwt)
return Helpers.MakeRequest(HttpMethod.Delete, $"{Url}/admin/users/{uid}", data, CreateAuthedRequestHeaders(jwt));
}

public Task<Settings?> Settings()
{
return Helpers.MakeRequest<Settings>(HttpMethod.Get, $"{Url}/settings");
}

/// <summary>
/// Generates a new JWT
/// </summary>
Expand Down
Loading