feat: add some fediverse authentication code
* create applications on instances * generate authorize URLs * exchange oauth code for token and user info (untested) * recreate mastodon app on authentication failure
This commit is contained in:
parent
a4ca0902a3
commit
0077a165b5
8 changed files with 497 additions and 0 deletions
|
@ -0,0 +1,40 @@
|
|||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using NodaTime;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Foxnouns.Backend.Database.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
[DbContext(typeof(DatabaseContext))]
|
||||
[Migration("20241006125003_AddFediverseAccessTokens")]
|
||||
public partial class AddFediverseAccessTokens : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "access_token",
|
||||
table: "fediverse_applications",
|
||||
type: "text",
|
||||
nullable: true
|
||||
);
|
||||
|
||||
migrationBuilder.AddColumn<Instant>(
|
||||
name: "token_valid_until",
|
||||
table: "fediverse_applications",
|
||||
type: "timestamp with time zone",
|
||||
nullable: true
|
||||
);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(name: "access_token", table: "fediverse_applications");
|
||||
|
||||
migrationBuilder.DropColumn(name: "token_valid_until", table: "fediverse_applications");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -107,6 +107,10 @@ namespace Foxnouns.Backend.Database.Migrations
|
|||
.HasColumnType("bigint")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<string>("AccessToken")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("access_token");
|
||||
|
||||
b.Property<string>("ClientId")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
|
@ -126,6 +130,10 @@ namespace Foxnouns.Backend.Database.Migrations
|
|||
.HasColumnType("integer")
|
||||
.HasColumnName("instance_type");
|
||||
|
||||
b.Property<Instant?>("TokenValidUntil")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("token_valid_until");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_fediverse_applications");
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
using NodaTime;
|
||||
|
||||
namespace Foxnouns.Backend.Database.Models;
|
||||
|
||||
public class FediverseApplication : BaseModel
|
||||
|
@ -6,6 +8,10 @@ public class FediverseApplication : BaseModel
|
|||
public required string ClientId { get; set; }
|
||||
public required string ClientSecret { get; set; }
|
||||
public required FediverseInstanceType InstanceType { get; set; }
|
||||
|
||||
// These are for ensuring the application is still valid.
|
||||
public string? AccessToken { get; set; }
|
||||
public Instant? TokenValidUntil { get; set; }
|
||||
}
|
||||
|
||||
public enum FediverseInstanceType
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue