Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="services"></param>
        public static void RegisterTypes(IServiceCollection services)
        {
            services.AddRefitClient <IFacebookGraphClient>()
            .ConfigureHttpClient(c => c.BaseAddress = new Uri(Constants.Secrets.IdentityProviderSettings.Facebook.GraphBaseUri))
            .AddHttpMessageHandler <HttpBootstrapHandler>();
            services.AddRefitClient <IGoogleGraphClient>()
            .ConfigureHttpClient(c => c.BaseAddress = new Uri(Constants.Secrets.IdentityProviderSettings.Google.GraphBaseUri))
            .AddHttpMessageHandler <HttpBootstrapHandler>();

            IBaseConfiguration configurationProvider = null;

            services.AddSingleton <IExternalIdentityProvider, FacebookIdentityProvider>(serviceProvider =>
            {
                configurationProvider = serviceProvider.GetService <IBaseConfiguration>();
                IFacebookGraphClient facebookGraphClient = serviceProvider.GetService <IFacebookGraphClient>();
                return(new FacebookIdentityProvider(configurationProvider.FaceBookAuthenticationSettings, facebookGraphClient));
            });

            services.AddSingleton <IExternalIdentityProvider, GoogleIdentityProvider>(serviceProvider =>
            {
                configurationProvider = serviceProvider.GetService <IBaseConfiguration>();
                IGoogleGraphClient googleGraphClient = serviceProvider.GetService <IGoogleGraphClient>();
                return(new GoogleIdentityProvider(configurationProvider.GoogleAuthenticationSettings, googleGraphClient));
            });

            services.AddSingleton <IExternalIdentityProviderFactory, ExternalIdentityProviderFactory>();

            services.AddRefitClient <IFacebookUserClient>()
            .ConfigureHttpClient(c => c.BaseAddress = new Uri(Constants.Secrets.IdentityProviderSettings.Facebook.GraphBaseUri))
            .AddHttpMessageHandler <HttpBootstrapHandler>();
            services.AddRefitClient <IGoogleUserClient>()
            .ConfigureHttpClient(c => c.BaseAddress = new Uri(Constants.Secrets.IdentityProviderSettings.Google.GraphBaseUri))
            .AddHttpMessageHandler <HttpBootstrapHandler>();

            services.AddSingleton <IFacebookUserServiceClient, FacebookUserServiceClient>();
            services.AddSingleton <IGoogleUserServiceClient, GoogleUserServiceClient>();

            services.AddDbContextPool <IAccountDbContext, AccountDbContext>((serviceProvider, options) =>
            {
                configurationProvider = serviceProvider.GetService <IBaseConfiguration>();
                options.UseLazyLoadingProxies();
                options.UseMySql(configurationProvider.DatabaseConnectionIdentifier.RootConnection,
                                 builderOptions => builderOptions.ServerVersion(new Version(5, 7), Pomelo.EntityFrameworkCore.MySql.Infrastructure.ServerType.MySql));
            });

            services.AddScoped <IRoleRepository, RoleRepository>();
            services.AddScoped <IUserRepository, UserRepository>();

            services.AddScoped <IRoleProvider, RoleProvider>();
            services.AddScoped <IAccountProvider, AccountProvider>();
        }
Exemplo n.º 2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="identityProviderSettings"></param>
 /// <param name="facebookGraphClient"></param>
 public FacebookIdentityProvider(IIdentityProviderSettings identityProviderSettings, IFacebookGraphClient facebookGraphClient)
 {
     _identityProviderSettings = identityProviderSettings;
     _facebookGraphClient      = facebookGraphClient;
 }