Versatile OpenID Connect stack for ASP.NET Core and Microsoft.Owin (compatible with ASP.NET 4.6.1)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

99 lines
4.5 KiB

/*
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
* See https://github.com/openiddict/openiddict-core for more information concerning
* the license and the contributors participating to this project.
*/
using System.ComponentModel;
using System.Data.Entity.ModelConfiguration;
using System.Diagnostics.CodeAnalysis;
using System.Linq.Expressions;
using OpenIddict.EntityFramework.Models;
namespace OpenIddict.EntityFramework;
/// <summary>
/// Defines a relational mapping for the application entity.
/// </summary>
/// <typeparam name="TApplication">The type of the application entity.</typeparam>
/// <typeparam name="TAuthorization">The type of the authorization entity.</typeparam>
/// <typeparam name="TSession">The type of the session entity.</typeparam>
/// <typeparam name="TToken">The type of the token entity.</typeparam>
/// <typeparam name="TKey">The type of the primary key.</typeparam>
[EditorBrowsable(EditorBrowsableState.Never)]
public sealed class OpenIddictEntityFrameworkApplicationConfiguration<
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TApplication,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TAuthorization,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TSession,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TToken,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TKey> : EntityTypeConfiguration<TApplication>
where TApplication : OpenIddictEntityFrameworkApplication<TKey, TAuthorization, TSession, TToken>
where TAuthorization : OpenIddictEntityFrameworkAuthorization<TKey, TApplication, TSession, TToken>
where TSession : OpenIddictEntityFrameworkSession<TKey, TApplication, TAuthorization, TToken>
where TToken : OpenIddictEntityFrameworkToken<TKey, TApplication, TAuthorization, TSession>
where TKey : notnull, IEquatable<TKey>
{
public OpenIddictEntityFrameworkApplicationConfiguration()
{
// Warning: optional foreign keys MUST NOT be added as CLR properties because
// Entity Framework would throw an exception due to the TKey generic parameter
// being non-nullable when using value types like short, int, long or Guid.
HasMany(static application => application.Authorizations)
.WithOptional(static authorization => authorization.Application!)
.Map(static association =>
{
association.MapKey(nameof(OpenIddictEntityFrameworkAuthorization.Application) +
nameof(OpenIddictEntityFrameworkApplication.Id));
});
Property(static application => application.ApplicationType)
.HasMaxLength(50);
Property(static application => application.ClientId)
.HasMaxLength(100);
HasIndex(static application => application.ClientId)
.IsUnique();
Property(static application => application.ClientType)
.HasMaxLength(50);
Property(static application => application.ConcurrencyToken)
.HasMaxLength(50)
.IsConcurrencyToken();
Property(static application => application.ConsentType)
.HasMaxLength(50);
HasKey(static application => application.Id);
if (typeof(TKey) == typeof(string))
{
var parameter = Expression.Parameter(typeof(TApplication), "application");
var property = Expression.Property(parameter,
typeof(TApplication).GetProperty(nameof(OpenIddictEntityFrameworkApplication.Id))!);
var lambda = Expression.Lambda<Func<TApplication, string>>(property, parameter);
Property(lambda).HasMaxLength(100);
}
HasMany(static application => application.Sessions)
.WithOptional(static session => session.Application!)
.Map(static association =>
{
association.MapKey(nameof(OpenIddictEntityFrameworkSession.Application) +
nameof(OpenIddictEntityFrameworkApplication.Id));
});
HasMany(static application => application.Tokens)
.WithOptional(static token => token.Application!)
.Map(static association =>
{
association.MapKey(nameof(OpenIddictEntityFrameworkToken.Application) +
nameof(OpenIddictEntityFrameworkApplication.Id));
});
ToTable("OpenIddictApplications");
}
}