public static IdentityBuilder AddIdentityMongoDbProvider <TUser, TRole>(this IServiceCollection services, Action <IdentityOptions> setupIdentityAction, Action <MongoIdentityOptions> setupDatabaseAction) where TUser : ApplicationUser where TRole : Role { MongoIdentityOptions dbOptions = new MongoIdentityOptions(); setupDatabaseAction(dbOptions); IdentityBuilder builder = services.AddIdentity <TUser, TRole>(setupIdentityAction ?? (x => { })); builder.AddRoleStore <RoleStore <TRole> >() .AddUserStore <UserStore <TUser, TRole> >() .AddUserManager <UserManager <TUser> >() .AddRoleManager <RoleManager <TRole> >() .AddDefaultTokenProviders(); IMongoCollection <TUser> userCollection = MongoUtil.FromConnectionString <TUser>(dbOptions.ConnectionString, dbOptions.DatabaseName, dbOptions.UsersCollection); IMongoCollection <TRole> roleCollection = MongoUtil.FromConnectionString <TRole>(dbOptions.ConnectionString, dbOptions.DatabaseName, dbOptions.RolesCollection); services.AddSingleton(x => userCollection); services.AddSingleton(x => roleCollection); // Identity Services services.AddTransient <IUserStore <TUser> >(x => new UserStore <TUser, TRole>(userCollection, roleCollection, x.GetService <ILookupNormalizer>())); services.AddTransient <IRoleStore <TRole> >(x => new RoleStore <TRole>(roleCollection)); Task <System.Collections.Generic.List <TUser> > all = userCollection.All(); all.Wait(); return(builder); }
public static IdentityBuilder AddIdentityMongoDbProvider <TUser, TRole>(this IServiceCollection services, Action <IdentityOptions> setupIdentityAction, Action <MongoIdentityOptions> setupDatabaseAction) where TUser : MongoUser where TRole : MongoRole { var dbOptions = new MongoIdentityOptions(); setupDatabaseAction(dbOptions); var builder = services.AddIdentity <TUser, TRole>(setupIdentityAction ?? (x => { })); builder.AddRoleStore <RoleStore <TRole> >() .AddUserStore <UserStore <TUser, TRole> >() .AddUserManager <UserManager <TUser> >() .AddRoleManager <RoleManager <TRole> >() .AddDefaultTokenProviders(); var userCollection = MongoUtil.FromConnectionString <TUser>(dbOptions.ConnectionString, dbOptions.UsersCollection); var roleCollection = MongoUtil.FromConnectionString <TRole>(dbOptions.ConnectionString, dbOptions.RolesCollection); services.AddSingleton(x => userCollection); services.AddSingleton(x => roleCollection); // Identity Services services.AddTransient <IRoleStore <TRole> >(x => new RoleStore <TRole>(roleCollection)); services.AddTransient <IUserStore <TUser> >(x => new UserStore <TUser, TRole>(userCollection, new RoleStore <TRole>(roleCollection), x.GetService <ILookupNormalizer>())); return(builder); }
/// <summary> /// Initializes a new instance of the <see cref="SecurityTestBase{T}"/> class. /// </summary> /// <param name="testFixture">The application test fixture.</param> protected SecurityTestBase(AppTestFixture <Startup> testFixture) : base(testFixture) { Environment.SetEnvironmentVariable("GOOGLE_CLIENT_ID", this.Faker.Random.AlphaNumeric(10)); Environment.SetEnvironmentVariable("GOOGLE_SECRET", this.Faker.Random.AlphaNumeric(10)); Environment.SetEnvironmentVariable("FACEBOOK_CLIENT_ID", this.Faker.Random.AlphaNumeric(10)); Environment.SetEnvironmentVariable("FACEBOOK_SECRET", this.Faker.Random.AlphaNumeric(10)); testFixture?.ConfigureTestServices(services => { // Setup user manager and role manager for integration test overriding the default implementation. var databaseOptions = new MongoIdentityOptions { ConnectionString = testFixture.RepositoryConfiguration.ConnectionString }; var userCollection = MongoUtil.FromConnectionString <UserAccount>(databaseOptions.ConnectionString, databaseOptions.UsersCollection); var roleCollection = MongoUtil.FromConnectionString <UserRole>(databaseOptions.ConnectionString, databaseOptions.RolesCollection); services.AddSingleton(x => userCollection); services.AddSingleton(x => roleCollection); services.AddTransient <IUserStore <UserAccount> >(x => new UserStore <UserAccount, UserRole>( userCollection, new RoleStore <UserRole>(roleCollection), x.GetService <ILookupNormalizer>())); services.AddTransient <IRoleStore <UserRole> >(x => new RoleStore <UserRole>(roleCollection)); }); }
public static IServiceCollection AddMongoDbExtensions(this IServiceCollection services, Action <MongoOptions> setupDatabaseAction) { var dbOptions = new MongoOptions(); setupDatabaseAction(dbOptions); var storedEventCollection = MongoUtil.FromConnectionString <StoredEvent>(dbOptions.ConnectionString, dbOptions.StoredEventCollection); var refreshTokenCollection = MongoUtil.FromConnectionString <RefreshToken>(dbOptions.ConnectionString, dbOptions.RefreshTokenCollection); services.AddSingleton(x => storedEventCollection); services.AddSingleton(x => refreshTokenCollection); return(services); }
public static IdentityBuilder AddIdentityMongoDbProvider <TUser, TRole, TKey>(this IServiceCollection services, Action <IdentityOptions> setupIdentityAction, Action <MongoIdentityOptions> setupDatabaseAction) where TKey : IEquatable <TKey> where TUser : MongoUser <TKey> where TRole : MongoRole <TKey> { var dbOptions = new MongoIdentityOptions(); setupDatabaseAction(dbOptions); var builder = services.AddIdentity <TUser, TRole>(setupIdentityAction ?? (x => { })); builder.AddRoleStore <RoleStore <TRole, TKey> >() .AddUserStore <UserStore <TUser, TRole, TKey> >() .AddUserManager <UserManager <TUser> >() .AddRoleManager <RoleManager <TRole> >() .AddDefaultTokenProviders(); var migrationCollection = MongoUtil.FromConnectionString <MigrationHistory>(dbOptions, dbOptions.MigrationCollection); Task.WaitAny(Migrator.Apply(migrationCollection)); var userCollection = MongoUtil.FromConnectionString <TUser>(dbOptions, dbOptions.UsersCollection); var roleCollection = MongoUtil.FromConnectionString <TRole>(dbOptions, dbOptions.RolesCollection); services.AddSingleton(x => userCollection); services.AddSingleton(x => roleCollection); // register custom ObjectId TypeConverter if (typeof(TKey) == typeof(ObjectId)) { RegisterTypeConverter <ObjectId, ObjectIdConverter>(); } // Identity Services services.AddTransient <IRoleStore <TRole> >(x => new RoleStore <TRole, TKey>(roleCollection)); services.AddTransient <IUserStore <TUser> >(x => new UserStore <TUser, TRole, TKey>(userCollection, new RoleStore <TRole, TKey>(roleCollection), x.GetService <ILookupNormalizer>())); return(builder); }
public NugetHistoryService(string connectionString) { history = MongoUtil.FromConnectionString <PackageHistory>(connectionString, "nugetHistory"); }
public MongoBlogService(string connectionString) { _post = MongoUtil.FromConnectionString <BlogPost>(connectionString, "blog"); }
public GridFileSystem(string connectionString, string collectionName) { _files = MongoUtil.FromConnectionString <GridFile>(connectionString, collectionName); _bucket = new GridFSBucket(_files.Database); }
public IdentityRoleCollection(string connectionString, string collectionName) { _roles = MongoUtil.FromConnectionString <TRole>(connectionString, collectionName); }
public SettingsService(string connectionString) { _collection = MongoUtil.FromConnectionString <SettingSlot>(connectionString, "settings"); }
public IdentityUserCollection(string connectionString, string collectionName) { _users = MongoUtil.FromConnectionString <TUser>(connectionString, collectionName); }
public MongoScriptService(string connectionString, IServiceProvider services) { _services = services; _scripts = MongoUtil.FromConnectionString <Script>(connectionString, "scripts"); }
public YoutubeService(string connectionString) { _video = MongoUtil.FromConnectionString <SubtitledVideo>(connectionString, "shyopedia"); }
public MongoFeedService(string connectionString) { _feeds = MongoUtil.FromConnectionString <Feed>(connectionString, "feeds"); _news = MongoUtil.FromConnectionString <FeedNews>(connectionString, "news"); }