clean up RemoteAuthService

This commit is contained in:
sam 2024-12-10 14:09:32 +01:00
parent 3338243cea
commit 80b7f192f1
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
4 changed files with 17 additions and 25 deletions

View file

@ -12,8 +12,7 @@
// //
// You should have received a copy of the GNU Affero General Public License // You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
using System.Diagnostics.CodeAnalysis; using System.Text.Json.Serialization;
using JetBrains.Annotations;
namespace Foxnouns.Backend.Services.Auth; namespace Foxnouns.Backend.Services.Auth;
@ -66,22 +65,12 @@ public partial class RemoteAuthService
if (user == null) if (user == null)
throw new FoxnounsError("Discord user response was null"); throw new FoxnounsError("Discord user response was null");
return new RemoteUser(user.id, user.username); return new RemoteUser(user.Id, user.Username);
} }
[SuppressMessage( // ReSharper disable once ClassNeverInstantiated.Local
"ReSharper", private record DiscordUserResponse(
"InconsistentNaming", [property: JsonPropertyName("id")] string Id,
Justification = "Easier to use snake_case here, rather than passing in JSON converter options" [property: JsonPropertyName("username")] string Username
)] );
[UsedImplicitly]
private record DiscordTokenResponse(string access_token, string token_type);
[SuppressMessage(
"ReSharper",
"InconsistentNaming",
Justification = "Easier to use snake_case here, rather than passing in JSON converter options"
)]
[UsedImplicitly]
private record DiscordUserResponse(string id, string username);
} }

View file

@ -12,7 +12,6 @@
// //
// You should have received a copy of the GNU Affero General Public License // You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
using System.Diagnostics.CodeAnalysis;
using System.Text; using System.Text;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
@ -69,7 +68,7 @@ public partial class RemoteAuthService
return new RemoteUser(user.Id, user.Email); return new RemoteUser(user.Id, user.Email);
} }
[SuppressMessage("ReSharper", "ClassNeverInstantiated.Local")] // ReSharper disable once ClassNeverInstantiated.Local
private record GoogleTokenResponse([property: JsonPropertyName("id_token")] string IdToken); private record GoogleTokenResponse([property: JsonPropertyName("id_token")] string IdToken);
private record GoogleUser( private record GoogleUser(

View file

@ -14,6 +14,8 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
// ReSharper disable ClassNeverInstantiated.Local
namespace Foxnouns.Backend.Services.Auth; namespace Foxnouns.Backend.Services.Auth;
public partial class RemoteAuthService public partial class RemoteAuthService
@ -83,11 +85,6 @@ public partial class RemoteAuthService
return new RemoteUser(blog.Uuid, blog.Name); return new RemoteUser(blog.Uuid, blog.Name);
} }
private record OauthTokenResponse(
[property: JsonPropertyName("access_token")] string AccessToken,
[property: JsonPropertyName("token_type")] string TokenType
);
// tumblr why // tumblr why
private record TumblrData( private record TumblrData(
[property: JsonPropertyName("meta")] TumblrMeta Meta, [property: JsonPropertyName("meta")] TumblrMeta Meta,

View file

@ -13,6 +13,7 @@
// You should have received a copy of the GNU Affero General Public License // You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;
using System.Web; using System.Web;
using Foxnouns.Backend.Database; using Foxnouns.Backend.Database;
using Foxnouns.Backend.Database.Models; using Foxnouns.Backend.Database.Models;
@ -35,6 +36,12 @@ public partial class RemoteAuthService(
public record RemoteUser(string Id, string Username); public record RemoteUser(string Id, string Username);
[SuppressMessage("ReSharper", "ClassNeverInstantiated.Local")]
private record OauthTokenResponse(
[property: JsonPropertyName("access_token")] string AccessToken,
[property: JsonPropertyName("token_type")] string TokenType
);
/// <summary> /// <summary>
/// Validates whether a user can still add a new account of the given AuthType, and throws an error if they can't. /// Validates whether a user can still add a new account of the given AuthType, and throws an error if they can't.
/// </summary> /// </summary>