From bda1e81c87a34bc0e6d2ce805f706a726087e957 Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Sun, 30 Jan 2022 01:30:58 +0100 Subject: feat: WIP: Map github logins When github is used for login, we want to create a mapping to a regular user in our database. This is mainly so that we don't have to change the PK in our database or add a column to it. --- src/server/Utilities/HandleGithubCreatingTicket.cs | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/server/Utilities/HandleGithubCreatingTicket.cs (limited to 'src/server/Utilities/HandleGithubCreatingTicket.cs') diff --git a/src/server/Utilities/HandleGithubCreatingTicket.cs b/src/server/Utilities/HandleGithubCreatingTicket.cs new file mode 100644 index 0000000..3ead322 --- /dev/null +++ b/src/server/Utilities/HandleGithubCreatingTicket.cs @@ -0,0 +1,30 @@ +using Microsoft.AspNetCore.Authentication.OAuth; +using Npgsql; + +namespace IOL.BookmarkThing.Server.Utilities; + +public static class HandleGithubCreatingTicket +{ + public static Task Handle(OAuthCreatingTicketContext context, IConfiguration configuration) { + var ghid = context.Identity?.FindFirst(p => p.Type == AppClaims.GITHUB_ID); + if (ghid == default) { + return default; + } + + var connstring = ConnectionStrings.AppDatabaseConnectionString(configuration); + var connection = new NpgsqlConnection(connstring); + connection.Open(); + var query = new NpgsqlCommand(@$"SELECT user_id FROM github_user_mappings WHERE github_id='{ghid}'", connection); + var x = query.ExecuteReader(); + foreach (var row in x) { + Console.WriteLine(JsonSerializer.Serialize(row)); + } + + // var claims = context.Identity.Claims.ToList(); + // foreach (var claim in claims) { + // context.Identity.RemoveClaim(claim); + // } + + return Task.CompletedTask; + } +} -- cgit v1.3