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

Allow for scoped signout #97

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions Gotrue/Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -542,12 +542,13 @@ public async Task<bool> UnlinkIdentity(string token, UserIdentity userIdentity)
/// Removes a logged-in session.
/// </summary>
/// <param name="jwt"></param>
/// <param name="scope"></param>
/// <returns></returns>
public Task<BaseResponse> SignOut(string jwt)
public Task<BaseResponse> SignOut(string jwt, SignOutScope scope = SignOutScope.Global)
{
var data = new Dictionary<string, string>();

return Helpers.MakeRequest(HttpMethod.Post, $"{Url}/logout", data, CreateAuthedRequestHeaders(jwt));
return Helpers.MakeRequest(HttpMethod.Post, $"{Url}/logout?scope={Core.Helpers.GetMappedToAttr(scope).Mapping}", data, CreateAuthedRequestHeaders(jwt));
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions Gotrue/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,9 @@ public Task<bool> UnlinkIdentity(UserIdentity userIdentity)
}

/// <inheritdoc />
public async Task SignOut()
public async Task SignOut(SignOutScope scope = SignOutScope.Global)
{
if (CurrentSession?.AccessToken != null) await _api.SignOut(CurrentSession.AccessToken);
if (CurrentSession?.AccessToken != null) await _api.SignOut(CurrentSession.AccessToken, scope);
UpdateSession(null);
NotifyAuthStateChange(SignedOut);
}
Expand Down
12 changes: 11 additions & 1 deletion Gotrue/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,15 @@ public enum SignUpType
Email,
Phone
}
}

public enum SignOutScope
{
[MapTo("global")]
Global,
[MapTo("local")]
Local,
[MapTo("others")]
Others
}
}
}
2 changes: 1 addition & 1 deletion Gotrue/Interfaces/IGotrueApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public interface IGotrueApi<TUser, TSession> : IGettableHeaders
Task<TSession?> SignInAnonymously(SignInAnonymouslyOptions? options = null);
Task<SSOResponse?> SignInWithSSO(Guid providerId, SignInWithSSOOptions? options = null);
Task<SSOResponse?> SignInWithSSO(string domain, SignInWithSSOOptions? options = null);
Task<BaseResponse> SignOut(string jwt);
Task<BaseResponse> SignOut(string jwt, SignOutScope scope = SignOutScope.Global);
Task<TSession?> SignUpWithEmail(string email, string password, SignUpOptions? options = null);
Task<TSession?> SignUpWithPhone(string phone, string password, SignUpOptions? options = null);
Task<TUser?> UpdateUser(string jwt, UserAttributes attributes);
Expand Down
5 changes: 3 additions & 2 deletions Gotrue/Interfaces/IGotrueClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,11 @@ public interface IGotrueClient<TUser, TSession> : IGettableHeaders
Task<bool> Reauthenticate();

/// <summary>
/// Signs out a user and invalidates the current token.
/// Signs out and invalidates all sessions for a user.
/// </summary>
/// <param name="scope">Determines which sessions should be invalidated. By default, it will invalidate all session for a user</param>
/// <returns></returns>
Task SignOut();
Task SignOut(SignOutScope scope = SignOutScope.Global);

/// <summary>
/// Updates a User.
Expand Down
Loading