public OpenIddictController( [NotNull] OpenIddictServices <TUser, TApplication> services, [NotNull] IOptions <OpenIddictOptions> options) { Services = services; Options = options.Value; }
public static IdentityBuilder AddOpenIddictCore <TApplication>( [NotNull] this IdentityBuilder builder, [NotNull] Action <OpenIddictServices> configuration) where TApplication : class { builder.Services.AddAuthentication(); builder.Services.AddCaching(); builder.Services.TryAddSingleton( typeof(IOpenIdConnectServerProvider), typeof(OpenIddictProvider <,>).MakeGenericType( builder.UserType, typeof(TApplication))); builder.Services.TryAddScoped( typeof(OpenIddictManager <,>).MakeGenericType( builder.UserType, typeof(TApplication))); var services = new OpenIddictServices(builder.Services) { ApplicationType = typeof(TApplication), RoleType = builder.RoleType, UserType = builder.UserType }; builder.Services.TryAddSingleton(services); configuration(services); return(builder); }
private static Type ResolveKeyType([NotNull] OpenIddictServices services) { TypeInfo type; for (type = services.UserType.GetTypeInfo(); type != null; type = type.BaseType?.GetTypeInfo()) { if (!type.IsGenericType) { continue; } var definition = type.GetGenericTypeDefinition(); if (definition == null) { continue; } if (definition != typeof(IdentityUser <>)) { continue; } return(type.AsType().GetGenericArguments().Single()); } throw new InvalidOperationException( "The type of the key identifier used by the user " + $"entity '{services.UserType}' cannot be automatically inferred."); }
public static OpenIddictServices UseEntityFramework([NotNull] this OpenIddictServices services) { services.Services.AddScoped( typeof(IOpenIddictStore <,>).MakeGenericType(services.UserType, services.ApplicationType), typeof(OpenIddictStore <, , , ,>).MakeGenericType( /* TUser: */ services.UserType, /* TApplication: */ services.ApplicationType, /* TRole: */ services.RoleType, /* TContext: */ ResolveContextType(services), /* TKey: */ ResolveKeyType(services))); return(services); }
private static Type ResolveContextType([NotNull] OpenIddictServices services) { var service = (from registration in services.Services where registration.ServiceType.IsConstructedGenericType let definition = registration.ServiceType.GetGenericTypeDefinition() where definition == typeof(IUserStore <>) select registration.ImplementationType).SingleOrDefault(); if (service == null) { throw new InvalidOperationException( "The type of the database context cannot be automatically inferred. " + "Make sure 'AddOpenIddict()' is the last chained call when configuring the services."); } TypeInfo type; for (type = service.GetTypeInfo(); type != null; type = type.BaseType?.GetTypeInfo()) { if (!type.IsGenericType) { continue; } var definition = type.GetGenericTypeDefinition(); if (definition == null) { continue; } if (definition != typeof(UserStore <, , ,>)) { continue; } return((from argument in type.AsType().GetGenericArguments() where typeof(DbContext).IsAssignableFrom(argument) select argument).Single()); } throw new InvalidOperationException("The type of the database context cannot be automatically inferred."); }
public CustomOpenIddictManager(OpenIddictServices <ApplicationUser, Application> services) : base(services) { }
public OpenIddictController([NotNull] OpenIddictServices <TUser, TApplication> services) { Services = services; }