From 28cc94bc7dc5a27b10a88f1909a990a1cb31028b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Wed, 9 Mar 2016 15:05:29 +0100 Subject: [PATCH] Update Application to accept a TKey generic parameter --- src/OpenIddict.EF/OpenIddictContext.cs | 2 +- src/OpenIddict.EF/OpenIddictStore.cs | 7 +++++-- src/OpenIddict.Models/Application.cs | 8 ++++++-- src/OpenIddict/OpenIddictExtensions.cs | 2 +- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/OpenIddict.EF/OpenIddictContext.cs b/src/OpenIddict.EF/OpenIddictContext.cs index f7a1b837..a7fee4ab 100644 --- a/src/OpenIddict.EF/OpenIddictContext.cs +++ b/src/OpenIddict.EF/OpenIddictContext.cs @@ -13,7 +13,7 @@ using OpenIddict.Models; namespace OpenIddict { public class OpenIddictContext : IdentityDbContext where TUser : IdentityUser - where TApplication : Application + where TApplication : Application where TRole : IdentityRole where TKey : IEquatable { public OpenIddictContext() { } diff --git a/src/OpenIddict.EF/OpenIddictStore.cs b/src/OpenIddict.EF/OpenIddictStore.cs index 78122392..88a643e2 100644 --- a/src/OpenIddict.EF/OpenIddictStore.cs +++ b/src/OpenIddict.EF/OpenIddictStore.cs @@ -1,4 +1,5 @@ using System; +using System.ComponentModel; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; @@ -8,7 +9,7 @@ using OpenIddict.Models; namespace OpenIddict { public class OpenIddictStore : IOpenIddictStore where TUser : IdentityUser - where TApplication : Application + where TApplication : Application where TContext : DbContext where TKey : IEquatable { public OpenIddictStore(TContext context) { @@ -25,7 +26,9 @@ namespace OpenIddict { } public virtual Task FindApplicationByIdAsync(string identifier, CancellationToken cancellationToken) { - return Applications.SingleOrDefaultAsync(application => application.Id == identifier, cancellationToken); + var key = (TKey) TypeDescriptor.GetConverter(typeof(TKey)).ConvertFromInvariantString(identifier); + + return Applications.SingleOrDefaultAsync(application => application.Id.Equals(key), cancellationToken); } public virtual Task FindApplicationByLogoutRedirectUri(string url, CancellationToken cancellationToken) { diff --git a/src/OpenIddict.Models/Application.cs b/src/OpenIddict.Models/Application.cs index 99a985b3..7d0833ea 100644 --- a/src/OpenIddict.Models/Application.cs +++ b/src/OpenIddict.Models/Application.cs @@ -4,9 +4,13 @@ * the license and the contributors participating to this project. */ +using System; + namespace OpenIddict.Models { - public class Application { - public string Id { get; set; } + public class Application : Application { } + + public class Application where TKey : IEquatable { + public TKey Id { get; set; } public string DisplayName { get; set; } public string RedirectUri { get; set; } public string LogoutRedirectUri { get; set; } diff --git a/src/OpenIddict/OpenIddictExtensions.cs b/src/OpenIddict/OpenIddictExtensions.cs index 5e93515d..810c9009 100644 --- a/src/OpenIddict/OpenIddictExtensions.cs +++ b/src/OpenIddict/OpenIddictExtensions.cs @@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Builder { } public static IdentityBuilder AddOpenIddict([NotNull] this IdentityBuilder builder) - where TApplication : Application { + where TApplication : class { if (builder == null) { throw new ArgumentNullException(nameof(builder)); }