feat: authentication through Discord OAuth2

This commit is contained in:
Lucien Cartier-Tilet 2024-08-10 11:06:18 +02:00
parent 1125bc4a38
commit ff90b1959f
Signed by: phundrak
GPG Key ID: 35A9399AF8F1929C
4 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,5 @@
-- Add down migration script here
ALTER TABLE IF EXISTS public.sessions DROP CONSTRAINT IF EXISTS sessions_user_id_users_fk;
DROP TABLE IF EXISTS public.sessions;
DROP TABLE IF EXISTS public.users;
DROP EXTENSION IF EXISTS "uuid-ossp";

View File

@ -0,0 +1,29 @@
-- Add up migration script here
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE TABLE IF NOT EXISTS public.users
(
id uuid NOT NULL DEFAULT uuid_generate_v4(),
email character varying(255) NOT NULL,
created_at timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
last_updated timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id),
CONSTRAINT users_email_unique UNIQUE (email)
);
CREATE TABLE IF NOT EXISTS public.sessions
(
id uuid NOT NULL DEFAULT uuid_generate_v4(),
user_id uuid NOT NULL,
session_id character varying NOT NULL,
expires_at timestamp with time zone NOT NULL,
PRIMARY KEY (id),
CONSTRAINT sessions_user_id_unique UNIQUE (user_id)
);
ALTER TABLE IF EXISTS public.sessions
ADD CONSTRAINT sessions_user_id_users_fk FOREIGN KEY (user_id)
REFERENCES public.users (id) MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE
NOT VALID;

View File

@ -16,3 +16,7 @@ email:
user: user@gege-jdr-backend.example
from: GegeJdrBackend <noreply@gege-jdr-backend.example>
password: hunter2
discord:
client_id: changeme
client_secret: changeme

View File

@ -4,6 +4,7 @@ use sqlx::ConnectOptions;
pub struct Settings {
pub application: ApplicationSettings,
pub database: Database,
pub discord: Discord,
pub debug: bool,
pub email: EmailSettings,
pub frontend_url: String,
@ -164,6 +165,12 @@ pub struct EmailSettings {
pub from: String,
}
#[derive(Debug, serde::Deserialize, Clone, Default)]
pub struct Discord {
client_id: String,
client_secret: String,
}
#[cfg(test)]
mod tests {
use super::*;