From 750f8422733f7a74cbbf9769a18ad08900ebecf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Thu, 8 Oct 2020 17:13:03 +0200 Subject: [PATCH] Replace DateTimeOffset by DateTime in the EF Core/EF 6 models --- .../OpenIddictEntityFrameworkAuthorization.cs | 4 ++-- .../OpenIddictEntityFrameworkToken.cs | 8 ++++---- ...nIddictEntityFrameworkAuthorizationStore.cs | 9 +++++++-- .../OpenIddictEntityFrameworkTokenStore.cs | 18 ++++++++++++++---- ...enIddictEntityFrameworkCoreAuthorization.cs | 4 ++-- .../OpenIddictEntityFrameworkCoreToken.cs | 8 ++++---- ...ddictEntityFrameworkCoreApplicationStore.cs | 9 +-------- ...ictEntityFrameworkCoreAuthorizationStore.cs | 9 +++++++-- .../OpenIddictEntityFrameworkCoreTokenStore.cs | 18 ++++++++++++++---- .../OpenIddictMongoDbAuthorization.cs | 2 +- .../OpenIddictMongoDbToken.cs | 4 ++-- .../OpenIddictMongoDbAuthorizationStore.cs | 7 ++++++- .../Stores/OpenIddictMongoDbTokenStore.cs | 14 ++++++++++++-- 13 files changed, 76 insertions(+), 38 deletions(-) diff --git a/src/OpenIddict.EntityFramework.Models/OpenIddictEntityFrameworkAuthorization.cs b/src/OpenIddict.EntityFramework.Models/OpenIddictEntityFrameworkAuthorization.cs index 84954f1b..9dccd102 100644 --- a/src/OpenIddict.EntityFramework.Models/OpenIddictEntityFrameworkAuthorization.cs +++ b/src/OpenIddict.EntityFramework.Models/OpenIddictEntityFrameworkAuthorization.cs @@ -42,9 +42,9 @@ namespace OpenIddict.EntityFramework.Models public virtual string? ConcurrencyToken { get; set; } = Guid.NewGuid().ToString(); /// - /// Gets or sets the creation date of the current authorization. + /// Gets or sets the UTC creation date of the current authorization. /// - public virtual DateTimeOffset? CreationDate { get; set; } + public virtual DateTime? CreationDate { get; set; } /// /// Gets or sets the unique identifier associated with the current authorization. diff --git a/src/OpenIddict.EntityFramework.Models/OpenIddictEntityFrameworkToken.cs b/src/OpenIddict.EntityFramework.Models/OpenIddictEntityFrameworkToken.cs index ae21cab6..73547d5f 100644 --- a/src/OpenIddict.EntityFramework.Models/OpenIddictEntityFrameworkToken.cs +++ b/src/OpenIddict.EntityFramework.Models/OpenIddictEntityFrameworkToken.cs @@ -46,14 +46,14 @@ namespace OpenIddict.EntityFramework.Models public virtual string? ConcurrencyToken { get; set; } = Guid.NewGuid().ToString(); /// - /// Gets or sets the creation date of the current token. + /// Gets or sets the UTC creation date of the current token. /// - public virtual DateTimeOffset? CreationDate { get; set; } + public virtual DateTime? CreationDate { get; set; } /// - /// Gets or sets the expiration date of the current token. + /// Gets or sets the UTC expiration date of the current token. /// - public virtual DateTimeOffset? ExpirationDate { get; set; } + public virtual DateTime? ExpirationDate { get; set; } /// /// Gets or sets the unique identifier associated with the current token. diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkAuthorizationStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkAuthorizationStore.cs index a19076d1..d4c10464 100644 --- a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkAuthorizationStore.cs +++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkAuthorizationStore.cs @@ -420,7 +420,12 @@ namespace OpenIddict.EntityFramework throw new ArgumentNullException(nameof(authorization)); } - return new ValueTask(authorization.CreationDate); + if (authorization.CreationDate is null) + { + return new ValueTask(result: null); + } + + return new ValueTask(DateTime.SpecifyKind(authorization.CreationDate.Value, DateTimeKind.Utc)); } /// @@ -705,7 +710,7 @@ namespace OpenIddict.EntityFramework throw new ArgumentNullException(nameof(authorization)); } - authorization.CreationDate = date; + authorization.CreationDate = date?.UtcDateTime; return default; } diff --git a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkTokenStore.cs b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkTokenStore.cs index c02f10c7..277ae299 100644 --- a/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkTokenStore.cs +++ b/src/OpenIddict.EntityFramework/Stores/OpenIddictEntityFrameworkTokenStore.cs @@ -389,7 +389,12 @@ namespace OpenIddict.EntityFramework throw new ArgumentNullException(nameof(token)); } - return new ValueTask(token.CreationDate); + if (token.CreationDate is null) + { + return new ValueTask(result: null); + } + + return new ValueTask(DateTime.SpecifyKind(token.CreationDate.Value, DateTimeKind.Utc)); } /// @@ -400,7 +405,12 @@ namespace OpenIddict.EntityFramework throw new ArgumentNullException(nameof(token)); } - return new ValueTask(token.ExpirationDate); + if (token.ExpirationDate is null) + { + return new ValueTask(result: null); + } + + return new ValueTask(DateTime.SpecifyKind(token.ExpirationDate.Value, DateTimeKind.Utc)); } /// @@ -709,7 +719,7 @@ namespace OpenIddict.EntityFramework throw new ArgumentNullException(nameof(token)); } - token.CreationDate = date; + token.CreationDate = date?.UtcDateTime; return default; } @@ -722,7 +732,7 @@ namespace OpenIddict.EntityFramework throw new ArgumentNullException(nameof(token)); } - token.ExpirationDate = date; + token.ExpirationDate = date?.UtcDateTime; return default; } diff --git a/src/OpenIddict.EntityFrameworkCore.Models/OpenIddictEntityFrameworkCoreAuthorization.cs b/src/OpenIddict.EntityFrameworkCore.Models/OpenIddictEntityFrameworkCoreAuthorization.cs index 2007b92b..8be387e5 100644 --- a/src/OpenIddict.EntityFrameworkCore.Models/OpenIddictEntityFrameworkCoreAuthorization.cs +++ b/src/OpenIddict.EntityFrameworkCore.Models/OpenIddictEntityFrameworkCoreAuthorization.cs @@ -50,9 +50,9 @@ namespace OpenIddict.EntityFrameworkCore.Models public virtual string? ConcurrencyToken { get; set; } = Guid.NewGuid().ToString(); /// - /// Gets or sets the creation date of the current authorization. + /// Gets or sets the UTC creation date of the current authorization. /// - public virtual DateTimeOffset? CreationDate { get; set; } + public virtual DateTime? CreationDate { get; set; } /// /// Gets or sets the unique identifier associated with the current authorization. diff --git a/src/OpenIddict.EntityFrameworkCore.Models/OpenIddictEntityFrameworkCoreToken.cs b/src/OpenIddict.EntityFrameworkCore.Models/OpenIddictEntityFrameworkCoreToken.cs index 4495b909..5099de03 100644 --- a/src/OpenIddict.EntityFrameworkCore.Models/OpenIddictEntityFrameworkCoreToken.cs +++ b/src/OpenIddict.EntityFrameworkCore.Models/OpenIddictEntityFrameworkCoreToken.cs @@ -54,14 +54,14 @@ namespace OpenIddict.EntityFrameworkCore.Models public virtual string? ConcurrencyToken { get; set; } = Guid.NewGuid().ToString(); /// - /// Gets or sets the creation date of the current token. + /// Gets or sets the UTC creation date of the current token. /// - public virtual DateTimeOffset? CreationDate { get; set; } + public virtual DateTime? CreationDate { get; set; } /// - /// Gets or sets the expiration date of the current token. + /// Gets or sets the UTC expiration date of the current token. /// - public virtual DateTimeOffset? ExpirationDate { get; set; } + public virtual DateTime? ExpirationDate { get; set; } /// /// Gets or sets the unique identifier associated with the current token. diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreApplicationStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreApplicationStore.cs index cd9c71bc..289d670b 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreApplicationStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreApplicationStore.cs @@ -124,14 +124,7 @@ namespace OpenIddict.EntityFrameworkCore /// private DbSet Tokens => Context.Set(); - /// - /// Determines the number of applications that exist in the database. - /// - /// The that can be used to abort the operation. - /// - /// A that can be used to monitor the asynchronous operation, - /// whose result returns the number of applications in the database. - /// + /// public virtual async ValueTask CountAsync(CancellationToken cancellationToken) => await Applications.AsQueryable().LongCountAsync(cancellationToken); diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreAuthorizationStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreAuthorizationStore.cs index 3cba1382..bba232e6 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreAuthorizationStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreAuthorizationStore.cs @@ -488,7 +488,12 @@ namespace OpenIddict.EntityFrameworkCore throw new ArgumentNullException(nameof(authorization)); } - return new ValueTask(authorization.CreationDate); + if (authorization.CreationDate == null) + { + return new ValueTask(result: null); + } + + return new ValueTask(DateTime.SpecifyKind(authorization.CreationDate.Value, DateTimeKind.Utc)); } /// @@ -791,7 +796,7 @@ namespace OpenIddict.EntityFrameworkCore throw new ArgumentNullException(nameof(authorization)); } - authorization.CreationDate = date; + authorization.CreationDate = date?.UtcDateTime; return default; } diff --git a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreTokenStore.cs b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreTokenStore.cs index 89c4040f..e4211e81 100644 --- a/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreTokenStore.cs +++ b/src/OpenIddict.EntityFrameworkCore/Stores/OpenIddictEntityFrameworkCoreTokenStore.cs @@ -441,7 +441,12 @@ namespace OpenIddict.EntityFrameworkCore throw new ArgumentNullException(nameof(token)); } - return new ValueTask(token.CreationDate); + if (token.CreationDate is null) + { + return new ValueTask(result: null); + } + + return new ValueTask(DateTime.SpecifyKind(token.CreationDate.Value, DateTimeKind.Utc)); } /// @@ -452,7 +457,12 @@ namespace OpenIddict.EntityFrameworkCore throw new ArgumentNullException(nameof(token)); } - return new ValueTask(token.ExpirationDate); + if (token.ExpirationDate is null) + { + return new ValueTask(result: null); + } + + return new ValueTask(DateTime.SpecifyKind(token.ExpirationDate.Value, DateTimeKind.Utc)); } /// @@ -784,7 +794,7 @@ namespace OpenIddict.EntityFrameworkCore throw new ArgumentNullException(nameof(token)); } - token.CreationDate = date; + token.CreationDate = date?.UtcDateTime; return default; } @@ -797,7 +807,7 @@ namespace OpenIddict.EntityFrameworkCore throw new ArgumentNullException(nameof(token)); } - token.ExpirationDate = date; + token.ExpirationDate = date?.UtcDateTime; return default; } diff --git a/src/OpenIddict.MongoDb.Models/OpenIddictMongoDbAuthorization.cs b/src/OpenIddict.MongoDb.Models/OpenIddictMongoDbAuthorization.cs index 317adf27..93b01a5e 100644 --- a/src/OpenIddict.MongoDb.Models/OpenIddictMongoDbAuthorization.cs +++ b/src/OpenIddict.MongoDb.Models/OpenIddictMongoDbAuthorization.cs @@ -32,7 +32,7 @@ namespace OpenIddict.MongoDb.Models public virtual string? ConcurrencyToken { get; set; } = Guid.NewGuid().ToString(); /// - /// Gets or sets the creation date of the current authorization. + /// Gets or sets the UTC creation date of the current authorization. /// public virtual DateTime? CreationDate { get; set; } diff --git a/src/OpenIddict.MongoDb.Models/OpenIddictMongoDbToken.cs b/src/OpenIddict.MongoDb.Models/OpenIddictMongoDbToken.cs index 5ba033ed..6f3e26c7 100644 --- a/src/OpenIddict.MongoDb.Models/OpenIddictMongoDbToken.cs +++ b/src/OpenIddict.MongoDb.Models/OpenIddictMongoDbToken.cs @@ -36,13 +36,13 @@ namespace OpenIddict.MongoDb.Models public virtual string? ConcurrencyToken { get; set; } = Guid.NewGuid().ToString(); /// - /// Gets or sets the creation date of the current token. + /// Gets or sets the UTC creation date of the current token. /// [BsonElement("creation_date"), BsonIgnoreIfNull] public virtual DateTime? CreationDate { get; set; } /// - /// Gets or sets the expiration date of the current token. + /// Gets or sets the UTC expiration date of the current token. /// [BsonElement("expiration_date"), BsonIgnoreIfNull] public virtual DateTime? ExpirationDate { get; set; } diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbAuthorizationStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbAuthorizationStore.cs index 010a7000..7d77b5d5 100644 --- a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbAuthorizationStore.cs +++ b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbAuthorizationStore.cs @@ -372,7 +372,12 @@ namespace OpenIddict.MongoDb throw new ArgumentNullException(nameof(authorization)); } - return new ValueTask(authorization.CreationDate); + if (authorization.CreationDate is null) + { + return new ValueTask(result: null); + } + + return new ValueTask(DateTime.SpecifyKind(authorization.CreationDate.Value, DateTimeKind.Utc)); } /// diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbTokenStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbTokenStore.cs index 6dd9bda8..210b9fee 100644 --- a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbTokenStore.cs +++ b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbTokenStore.cs @@ -370,7 +370,12 @@ namespace OpenIddict.MongoDb throw new ArgumentNullException(nameof(token)); } - return new ValueTask(token.CreationDate); + if (token.CreationDate is null) + { + return new ValueTask(result: null); + } + + return new ValueTask(DateTime.SpecifyKind(token.CreationDate.Value, DateTimeKind.Utc)); } /// @@ -381,7 +386,12 @@ namespace OpenIddict.MongoDb throw new ArgumentNullException(nameof(token)); } - return new ValueTask(token.ExpirationDate); + if (token.ExpirationDate is null) + { + return new ValueTask(result: null); + } + + return new ValueTask(DateTime.SpecifyKind(token.ExpirationDate.Value, DateTimeKind.Utc)); } ///