Browse Source

Update Application to accept a TKey generic parameter

pull/71/head
Kévin Chalet 11 years ago
parent
commit
28cc94bc7d
  1. 2
      src/OpenIddict.EF/OpenIddictContext.cs
  2. 7
      src/OpenIddict.EF/OpenIddictStore.cs
  3. 8
      src/OpenIddict.Models/Application.cs
  4. 2
      src/OpenIddict/OpenIddictExtensions.cs

2
src/OpenIddict.EF/OpenIddictContext.cs

@ -13,7 +13,7 @@ using OpenIddict.Models;
namespace OpenIddict { namespace OpenIddict {
public class OpenIddictContext<TUser, TApplication, TRole, TKey> : IdentityDbContext<TUser, TRole, TKey> public class OpenIddictContext<TUser, TApplication, TRole, TKey> : IdentityDbContext<TUser, TRole, TKey>
where TUser : IdentityUser<TKey> where TUser : IdentityUser<TKey>
where TApplication : Application where TApplication : Application<TKey>
where TRole : IdentityRole<TKey> where TRole : IdentityRole<TKey>
where TKey : IEquatable<TKey> { where TKey : IEquatable<TKey> {
public OpenIddictContext() { } public OpenIddictContext() { }

7
src/OpenIddict.EF/OpenIddictStore.cs

@ -1,4 +1,5 @@
using System; using System;
using System.ComponentModel;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
@ -8,7 +9,7 @@ using OpenIddict.Models;
namespace OpenIddict { namespace OpenIddict {
public class OpenIddictStore<TUser, TApplication, TContext, TKey> : IOpenIddictStore<TUser, TApplication> public class OpenIddictStore<TUser, TApplication, TContext, TKey> : IOpenIddictStore<TUser, TApplication>
where TUser : IdentityUser<TKey> where TUser : IdentityUser<TKey>
where TApplication : Application where TApplication : Application<TKey>
where TContext : DbContext where TContext : DbContext
where TKey : IEquatable<TKey> { where TKey : IEquatable<TKey> {
public OpenIddictStore(TContext context) { public OpenIddictStore(TContext context) {
@ -25,7 +26,9 @@ namespace OpenIddict {
} }
public virtual Task<TApplication> FindApplicationByIdAsync(string identifier, CancellationToken cancellationToken) { public virtual Task<TApplication> 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<TApplication> FindApplicationByLogoutRedirectUri(string url, CancellationToken cancellationToken) { public virtual Task<TApplication> FindApplicationByLogoutRedirectUri(string url, CancellationToken cancellationToken) {

8
src/OpenIddict.Models/Application.cs

@ -4,9 +4,13 @@
* the license and the contributors participating to this project. * the license and the contributors participating to this project.
*/ */
using System;
namespace OpenIddict.Models { namespace OpenIddict.Models {
public class Application { public class Application : Application<string> { }
public string Id { get; set; }
public class Application<TKey> where TKey : IEquatable<TKey> {
public TKey Id { get; set; }
public string DisplayName { get; set; } public string DisplayName { get; set; }
public string RedirectUri { get; set; } public string RedirectUri { get; set; }
public string LogoutRedirectUri { get; set; } public string LogoutRedirectUri { get; set; }

2
src/OpenIddict/OpenIddictExtensions.cs

@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Builder {
} }
public static IdentityBuilder AddOpenIddict<TApplication>([NotNull] this IdentityBuilder builder) public static IdentityBuilder AddOpenIddict<TApplication>([NotNull] this IdentityBuilder builder)
where TApplication : Application { where TApplication : class {
if (builder == null) { if (builder == null) {
throw new ArgumentNullException(nameof(builder)); throw new ArgumentNullException(nameof(builder));
} }

Loading…
Cancel
Save