Skip to content

Commit

Permalink
Shield: Change to date time with fixed offset
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielleHuisman committed Dec 29, 2024
1 parent 10f9a10 commit 3ee6b78
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,4 @@ target/
book/book/

# SeaORM
packages/storage/shield-seaorm/src/entities_template/
packages/storage/shield-sea-orm/src/entities_template/
14 changes: 7 additions & 7 deletions packages/core/shield/src/user.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt::Debug;

use async_trait::async_trait;
use chrono::{DateTime, Utc};
use chrono::{DateTime, FixedOffset};
use serde::{Deserialize, Serialize};

use crate::error::StorageError;
Expand Down Expand Up @@ -33,8 +33,8 @@ pub struct EmailAddress {
pub is_primary: bool,
pub is_verified: bool,
pub verification_token: Option<String>,
pub verification_token_expired_at: Option<DateTime<Utc>>,
pub verified_at: Option<DateTime<Utc>>,
pub verification_token_expired_at: Option<DateTime<FixedOffset>>,
pub verified_at: Option<DateTime<FixedOffset>>,
pub user_id: String,
}

Expand All @@ -44,8 +44,8 @@ pub struct CreateEmailAddress {
pub is_primary: bool,
pub is_verified: bool,
pub verification_token: Option<String>,
pub verification_token_expired_at: Option<DateTime<Utc>>,
pub verified_at: Option<DateTime<Utc>>,
pub verification_token_expired_at: Option<DateTime<FixedOffset>>,
pub verified_at: Option<DateTime<FixedOffset>>,
}

#[derive(Clone, Debug)]
Expand All @@ -54,8 +54,8 @@ pub struct UpdateEmailAddress {
pub is_primary: Option<bool>,
pub is_verified: Option<bool>,
pub verification_token: Option<Option<String>>,
pub verification_token_expired_at: Option<Option<DateTime<Utc>>>,
pub verified_at: Option<Option<DateTime<Utc>>>,
pub verification_token_expired_at: Option<Option<DateTime<FixedOffset>>>,
pub verified_at: Option<Option<DateTime<FixedOffset>>>,
}

#[cfg(test)]
Expand Down
8 changes: 4 additions & 4 deletions packages/providers/shield-oidc/src/connection.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use chrono::{DateTime, Utc};
use chrono::{DateTime, FixedOffset};

#[derive(Clone, Debug)]
pub struct OidcConnection {
Expand All @@ -8,7 +8,7 @@ pub struct OidcConnection {
pub access_token: String,
pub refresh_token: Option<String>,
pub id_token: Option<String>,
pub expired_at: Option<DateTime<Utc>>,
pub expired_at: Option<DateTime<FixedOffset>>,
pub scopes: Option<Vec<String>>,
pub subprovider_id: String,
pub user_id: String,
Expand All @@ -21,7 +21,7 @@ pub struct CreateOidcConnection {
pub access_token: String,
pub refresh_token: Option<String>,
pub id_token: Option<String>,
pub expired_at: Option<DateTime<Utc>>,
pub expired_at: Option<DateTime<FixedOffset>>,
pub scopes: Option<Vec<String>>,
pub subprovider_id: String,
pub user_id: String,
Expand All @@ -34,6 +34,6 @@ pub struct UpdateOidcConnection {
pub access_token: Option<String>,
pub refresh_token: Option<Option<String>>,
pub id_token: Option<Option<String>>,
pub expired_at: Option<Option<DateTime<Utc>>>,
pub expired_at: Option<Option<DateTime<FixedOffset>>>,
pub scopes: Option<Option<Vec<String>>>,
}
9 changes: 5 additions & 4 deletions packages/providers/shield-oidc/src/provider.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use async_trait::async_trait;
use chrono::{DateTime, Duration, Utc};
use chrono::{DateTime, Duration, FixedOffset, Utc};
use openidconnect::{
core::{CoreAuthenticationFlow, CoreGenderClaim, CoreTokenResponse},
reqwest::async_http_client,
Expand Down Expand Up @@ -463,7 +463,7 @@ type ParsedTokenResponse = (
String,
Option<String>,
Option<String>,
Option<DateTime<Utc>>,
Option<DateTime<FixedOffset>>,
Option<Vec<String>>,
);

Expand All @@ -481,9 +481,10 @@ fn parse_token_response(
.map(|id_token| id_token.to_string()),
match token_response.expires_in() {
Some(expires_in) => Some(
Utc::now()
(Utc::now()
+ Duration::from_std(expires_in)
.map_err(|err| ShieldError::Validation(err.to_string()))?,
.map_err(|err| ShieldError::Validation(err.to_string()))?)
.into(),
),
None => None,
},
Expand Down
8 changes: 4 additions & 4 deletions packages/storage/shield-sea-orm/src/entities/email_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ use serde::{Deserialize, Serialize};
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub created_at: DateTimeUtc,
pub updated_at: DateTimeUtc,
pub created_at: DateTimeWithTimeZone,
pub updated_at: DateTimeWithTimeZone,
#[sea_orm(unique)]
pub email: String,
pub is_primary: bool,
pub is_verified: bool,
pub verification_token: Option<String>,
pub verification_token_expired_at: Option<DateTimeUtc>,
pub verified_at: Option<DateTimeUtc>,
pub verification_token_expired_at: Option<DateTimeWithTimeZone>,
pub verified_at: Option<DateTimeWithTimeZone>,
#[cfg(feature = "entity")]
pub entity_id: Uuid,
#[cfg(not(feature = "entity"))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use serde::{Deserialize, Serialize};
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub created_at: DateTimeUtc,
pub updated_at: DateTimeUtc,
pub created_at: DateTimeWithTimeZone,
pub updated_at: DateTimeWithTimeZone,
pub email: String,
pub token: String,
pub expired_at: DateTimeUtc,
pub expired_at: DateTimeWithTimeZone,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
Expand Down
4 changes: 2 additions & 2 deletions packages/storage/shield-sea-orm/src/entities/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use serde::{Deserialize, Serialize};
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub created_at: DateTimeUtc,
pub updated_at: DateTimeUtc,
pub created_at: DateTimeWithTimeZone,
pub updated_at: DateTimeWithTimeZone,
#[sea_orm(column_type = "Text")]
pub name: String,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ pub enum OauthProviderVisibility {
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub created_at: DateTimeUtc,
pub updated_at: DateTimeUtc,
pub created_at: DateTimeWithTimeZone,
pub updated_at: DateTimeWithTimeZone,
pub name: String,
pub slug: Option<String>,
pub r#type: OauthProviderType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ use serde::{Deserialize, Serialize};
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub created_at: DateTimeUtc,
pub updated_at: DateTimeUtc,
pub created_at: DateTimeWithTimeZone,
pub updated_at: DateTimeWithTimeZone,
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>,
pub expired_at: Option<DateTimeWithTimeZone>,
#[sea_orm(column_type = "Text", nullable)]
pub scopes: Option<String>,
pub provider_id: Uuid,
Expand Down
4 changes: 2 additions & 2 deletions packages/storage/shield-sea-orm/src/entities/oidc_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ pub enum OidcProviderVisibility {
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub created_at: DateTimeUtc,
pub updated_at: DateTimeUtc,
pub created_at: DateTimeWithTimeZone,
pub updated_at: DateTimeWithTimeZone,
pub name: String,
pub slug: Option<String>,
pub r#type: OidcProviderType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use serde::{Deserialize, Serialize};
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub created_at: DateTimeUtc,
pub updated_at: DateTimeUtc,
pub created_at: DateTimeWithTimeZone,
pub updated_at: DateTimeWithTimeZone,
pub identifier: String,
#[sea_orm(column_type = "Text")]
pub token_type: String,
Expand All @@ -19,7 +19,7 @@ pub struct Model {
pub refresh_token: Option<String>,
#[sea_orm(column_type = "Text", nullable)]
pub id_token: Option<String>,
pub expired_at: Option<DateTimeUtc>,
pub expired_at: Option<DateTimeWithTimeZone>,
#[sea_orm(column_type = "Text", nullable)]
pub scopes: Option<String>,
pub provider_id: Uuid,
Expand Down
4 changes: 2 additions & 2 deletions packages/storage/shield-sea-orm/src/entities/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use serde::{Deserialize, Serialize};
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub created_at: DateTimeUtc,
pub updated_at: DateTimeUtc,
pub created_at: DateTimeWithTimeZone,
pub updated_at: DateTimeWithTimeZone,
#[cfg(not(feature = "entity"))]
#[sea_orm(column_type = "Text")]
pub name: String,
Expand Down

0 comments on commit 3ee6b78

Please sign in to comment.