-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Shield SeaORM: Add OAuth and OIDC providers
- Loading branch information
1 parent
cb08457
commit ee186ca
Showing
16 changed files
with
969 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
packages/storage/shield-seaorm/src/entities/oauth_provider.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.2 | ||
use sea_orm::entity::prelude::*; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)] | ||
#[sea_orm(table_name = "oauth_provider")] | ||
pub struct Model { | ||
#[sea_orm(primary_key, auto_increment = false)] | ||
pub id: Uuid, | ||
pub created_at: DateTimeUtc, | ||
pub updated_at: DateTimeUtc, | ||
pub name: String, | ||
pub slug: Option<String>, | ||
#[sea_orm(column_type = "custom(\"enum_text\")")] | ||
pub r#type: String, | ||
#[sea_orm(column_type = "custom(\"enum_text\")")] | ||
pub visibility: String, | ||
#[sea_orm(column_type = "Text")] | ||
pub client_id: String, | ||
#[sea_orm(column_type = "Text", nullable)] | ||
pub client_secret: Option<String>, | ||
#[sea_orm(column_type = "Text", nullable)] | ||
pub scopes: Option<String>, | ||
#[sea_orm(column_type = "Text", nullable)] | ||
pub redirect_url: Option<String>, | ||
#[sea_orm(column_type = "Text", nullable)] | ||
pub authorization_url: Option<String>, | ||
#[sea_orm(column_type = "Text", nullable)] | ||
pub authorization_url_params: Option<String>, | ||
#[sea_orm(column_type = "Text", nullable)] | ||
pub token_url: Option<String>, | ||
#[sea_orm(column_type = "Text", nullable)] | ||
pub token_url_params: Option<String>, | ||
#[sea_orm(column_type = "Text", nullable)] | ||
pub introspection_url: Option<String>, | ||
#[sea_orm(column_type = "Text", nullable)] | ||
pub introspection_url_params: Option<String>, | ||
#[sea_orm(column_type = "Text", nullable)] | ||
pub revocation_url: Option<String>, | ||
#[sea_orm(column_type = "Text", nullable)] | ||
pub revocation_url_params: Option<String>, | ||
#[sea_orm(column_type = "custom(\"enum_text\")")] | ||
pub pcke_code_challenge: String, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] | ||
pub enum Relation { | ||
#[sea_orm(has_many = "super::oauth_provider_connection::Entity")] | ||
OauthProviderConnection, | ||
} | ||
|
||
impl Related<super::oauth_provider_connection::Entity> for Entity { | ||
fn to() -> RelationDef { | ||
Relation::OauthProviderConnection.def() | ||
} | ||
} | ||
|
||
impl ActiveModelBehavior for ActiveModel {} |
60 changes: 60 additions & 0 deletions
60
packages/storage/shield-seaorm/src/entities/oauth_provider_connection.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.2 | ||
use sea_orm::entity::prelude::*; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)] | ||
#[sea_orm(table_name = "oauth_provider_connection")] | ||
pub struct Model { | ||
#[sea_orm(primary_key, auto_increment = false)] | ||
pub id: Uuid, | ||
pub created_at: DateTimeUtc, | ||
pub updated_at: DateTimeUtc, | ||
#[sea_orm(column_type = "Text")] | ||
pub identifier: String, | ||
#[sea_orm(column_type = "Text")] | ||
pub token_type: String, | ||
#[sea_orm(column_type = "Text")] | ||
pub access_token: String, | ||
#[sea_orm(column_type = "Text", nullable)] | ||
pub refresh_token: Option<String>, | ||
pub expired_at: Option<DateTimeUtc>, | ||
#[sea_orm(column_type = "Text", nullable)] | ||
pub scopes: Option<String>, | ||
pub provider_id: Uuid, | ||
pub user_id: Uuid, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] | ||
pub enum Relation { | ||
#[sea_orm( | ||
belongs_to = "super::oauth_provider::Entity", | ||
from = "Column::ProviderId", | ||
to = "super::oauth_provider::Column::Id", | ||
on_update = "Cascade", | ||
on_delete = "Cascade" | ||
)] | ||
OauthProvider, | ||
#[sea_orm( | ||
belongs_to = "super::user::Entity", | ||
from = "Column::UserId", | ||
to = "super::user::Column::Id", | ||
on_update = "Cascade", | ||
on_delete = "Cascade" | ||
)] | ||
User, | ||
} | ||
|
||
impl Related<super::oauth_provider::Entity> for Entity { | ||
fn to() -> RelationDef { | ||
Relation::OauthProvider.def() | ||
} | ||
} | ||
|
||
impl Related<super::user::Entity> for Entity { | ||
fn to() -> RelationDef { | ||
Relation::User.def() | ||
} | ||
} | ||
|
||
impl ActiveModelBehavior for ActiveModel {} |
67 changes: 67 additions & 0 deletions
67
packages/storage/shield-seaorm/src/entities/oidc_provider.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.2 | ||
use sea_orm::entity::prelude::*; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)] | ||
#[sea_orm(table_name = "oidc_provider")] | ||
pub struct Model { | ||
#[sea_orm(primary_key, auto_increment = false)] | ||
pub id: Uuid, | ||
pub created_at: DateTimeUtc, | ||
pub updated_at: DateTimeUtc, | ||
pub name: String, | ||
pub slug: Option<String>, | ||
#[sea_orm(column_type = "custom(\"enum_text\")")] | ||
pub r#type: String, | ||
#[sea_orm(column_type = "custom(\"enum_text\")")] | ||
pub visibility: String, | ||
#[sea_orm(column_type = "Text")] | ||
pub client_id: String, | ||
#[sea_orm(column_type = "Text", nullable)] | ||
pub client_secret: Option<String>, | ||
#[sea_orm(column_type = "Text", nullable)] | ||
pub scopes: Option<String>, | ||
#[sea_orm(column_type = "Text", nullable)] | ||
pub redirect_url: Option<String>, | ||
#[sea_orm(column_type = "Text", nullable)] | ||
pub issuer_url: Option<String>, | ||
#[sea_orm(column_type = "Text", nullable)] | ||
pub authorization_url: Option<String>, | ||
#[sea_orm(column_type = "Text", nullable)] | ||
pub authorization_url_params: Option<String>, | ||
#[sea_orm(column_type = "Text", nullable)] | ||
pub token_url: Option<String>, | ||
#[sea_orm(column_type = "Text", nullable)] | ||
pub token_url_params: Option<String>, | ||
#[sea_orm(column_type = "Text", nullable)] | ||
pub introspection_url: Option<String>, | ||
#[sea_orm(column_type = "Text", nullable)] | ||
pub introspection_url_params: Option<String>, | ||
#[sea_orm(column_type = "Text", nullable)] | ||
pub revocation_url: Option<String>, | ||
#[sea_orm(column_type = "Text", nullable)] | ||
pub revocation_url_params: Option<String>, | ||
#[sea_orm(column_type = "Text", nullable)] | ||
pub user_info_url: Option<String>, | ||
#[sea_orm(column_type = "Text", nullable)] | ||
pub json_web_key_set_url: Option<String>, | ||
#[sea_orm(column_type = "JsonBinary", nullable)] | ||
pub json_web_key_set: Option<Json>, | ||
#[sea_orm(column_type = "custom(\"enum_text\")")] | ||
pub pcke_code_challenge: String, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] | ||
pub enum Relation { | ||
#[sea_orm(has_many = "super::oidc_provider_connection::Entity")] | ||
OidcProviderConnection, | ||
} | ||
|
||
impl Related<super::oidc_provider_connection::Entity> for Entity { | ||
fn to() -> RelationDef { | ||
Relation::OidcProviderConnection.def() | ||
} | ||
} | ||
|
||
impl ActiveModelBehavior for ActiveModel {} |
62 changes: 62 additions & 0 deletions
62
packages/storage/shield-seaorm/src/entities/oidc_provider_connection.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.2 | ||
use sea_orm::entity::prelude::*; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)] | ||
#[sea_orm(table_name = "oidc_provider_connection")] | ||
pub struct Model { | ||
#[sea_orm(primary_key, auto_increment = false)] | ||
pub id: Uuid, | ||
pub created_at: DateTimeUtc, | ||
pub updated_at: DateTimeUtc, | ||
#[sea_orm(column_type = "Text")] | ||
pub identifier: String, | ||
#[sea_orm(column_type = "Text")] | ||
pub token_type: String, | ||
#[sea_orm(column_type = "Text")] | ||
pub access_token: String, | ||
#[sea_orm(column_type = "Text", nullable)] | ||
pub refresh_token: Option<String>, | ||
#[sea_orm(column_type = "Text", nullable)] | ||
pub id_token: Option<String>, | ||
pub expired_at: Option<DateTimeUtc>, | ||
#[sea_orm(column_type = "Text", nullable)] | ||
pub scopes: Option<String>, | ||
pub provider_id: Uuid, | ||
pub user_id: Uuid, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] | ||
pub enum Relation { | ||
#[sea_orm( | ||
belongs_to = "super::oidc_provider::Entity", | ||
from = "Column::ProviderId", | ||
to = "super::oidc_provider::Column::Id", | ||
on_update = "Cascade", | ||
on_delete = "Cascade" | ||
)] | ||
OidcProvider, | ||
#[sea_orm( | ||
belongs_to = "super::user::Entity", | ||
from = "Column::UserId", | ||
to = "super::user::Column::Id", | ||
on_update = "Cascade", | ||
on_delete = "Cascade" | ||
)] | ||
User, | ||
} | ||
|
||
impl Related<super::oidc_provider::Entity> for Entity { | ||
fn to() -> RelationDef { | ||
Relation::OidcProvider.def() | ||
} | ||
} | ||
|
||
impl Related<super::user::Entity> for Entity { | ||
fn to() -> RelationDef { | ||
Relation::User.def() | ||
} | ||
} | ||
|
||
impl ActiveModelBehavior for ActiveModel {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,19 @@ | ||
use core::CoreMigrator; | ||
pub mod core; | ||
pub mod providers; | ||
|
||
use async_trait::async_trait; | ||
use sea_orm_migration::{MigrationTrait, MigratorTrait}; | ||
|
||
mod core; | ||
mod providers; | ||
use self::{core::CoreMigrator, providers::ProvidersMigrator}; | ||
|
||
pub struct Migrator; | ||
|
||
#[async_trait] | ||
impl MigratorTrait for Migrator { | ||
fn migrations() -> Vec<Box<dyn MigrationTrait>> { | ||
#[allow(unused_mut)] | ||
let mut migrations = CoreMigrator::migrations(); | ||
|
||
#[cfg(feature = "provider-email")] | ||
{ | ||
use providers::email::ProviderEmailMigrator; | ||
migrations.extend(ProviderEmailMigrator::migrations()); | ||
} | ||
|
||
migrations | ||
CoreMigrator::migrations() | ||
.into_iter() | ||
.chain(ProvidersMigrator::migrations()) | ||
.collect() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
mod m20241210_203135_create_user; | ||
|
||
use async_trait::async_trait; | ||
use sea_orm_migration::{MigrationTrait, MigratorTrait}; | ||
|
||
mod m20241210_203135_create_user; | ||
|
||
pub struct CoreMigrator; | ||
|
||
#[async_trait] | ||
impl MigratorTrait for CoreMigrator { | ||
fn migrations() -> Vec<Box<dyn MigrationTrait>> { | ||
vec![Box::new(m20241210_203135_create_user::Migration)] | ||
vec![Box::new(self::m20241210_203135_create_user::Migration)] | ||
} | ||
} |
Oops, something went wrong.