Beispiel #1
0
        public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration)
        {
            services.AddDbContext <AppDbContext>(options =>
                                                 options.UseSqlite(configuration.GetConnectionString("DefaultConnection")));

            EmailSettings emailSettings = configuration.GetSection("EmailSettings").Get <EmailSettings>();

            services.AddSingleton <IEmailSender, EmailSender>(s => new EmailSender(emailSettings));

            services.AddIdentity <ApplicationUser, IdentityRole>(options => options.SignIn.RequireConfirmedAccount = true)
            .AddEntityFrameworkStores <AppDbContext>()
            .AddDefaultTokenProviders()
            .AddTokenProvider <DataProtectorTokenProvider <ApplicationUser> >(CustomTokenProviders.ResetAuthenticatorProvider);
            services.AddTransient <IIdentityService, IdentityService>();
            services.AddTransient <ISignInService, SignInService>();
            services.AddTransient <IRoleService, RoleService>();
            services.AddTransient <IExternalLoginService, ExternalLoginService>();
            services.AddTransient <IAuthenticatorService, AuthenticatorService>();

            services.Configure <IdentityOptions>(options =>
            {
                // Password settings.
                options.Password.RequireDigit           = false;
                options.Password.RequireLowercase       = false;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireUppercase       = false;
                options.Password.RequiredLength         = 6;
                options.Password.RequiredUniqueChars    = 1;

                // Lockout settings.
                options.Lockout.DefaultLockoutTimeSpan  = TimeSpan.FromMinutes(1);
                options.Lockout.MaxFailedAccessAttempts = 5;
                options.Lockout.AllowedForNewUsers      = true;

                // User settings.
                options.User.AllowedUserNameCharacters =
                    "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._@+";
                options.User.RequireUniqueEmail = true;
            });
            services.ConfigureApplicationCookie(options =>
            {
                // Cookie settings
                options.Cookie.HttpOnly = true;
                options.ExpireTimeSpan  = TimeSpan.FromMinutes(5);

                options.LoginPath         = "/Login";
                options.AccessDeniedPath  = "/AccessDenied";
                options.SlidingExpiration = true;
            });
            services.AddAuthentication()
            .AddGoogle(options =>
            {
                GoogleSettings googleSettings =
                    configuration.GetSection("GoogleSettings").Get <GoogleSettings>();

                options.ClientId     = googleSettings.ClientId;
                options.ClientSecret = googleSettings.ClientSecret;
            });
            return(services);
        }
Beispiel #2
0
 public GoogleProvider(
     IHttpClientFactory httpClientFactory,
     IOptions <GoogleSettings> googleSettings)
 {
     _httpClientFactory = httpClientFactory;
     _googleSettings    = googleSettings.Value;
 }
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            IsSystemPage = true;

            _settings = _settings.Load();

            try
            {
                if (Application != null && Request != null && !Request.Url.ToString().ToLower().Contains("_layouts") && !Request.Url.ToString().ToLower().Contains("forms"))
                {
                    IsSystemPage = false;
                }
            }
            catch { };

            try
            {
                if (SPContext.Current.Site.RootWeb.CurrentUser != null && !Settings.Current.Authenticated)
                {
                    TrackUsers = false;
                }
            }
            catch { };
        }
        public UserRepositoryTests()
        {
            var connection = new MongoConnection
            {
                ConnectionString = "mongodb://127.0.0.1:27017/edwardjenner",
                Database         = "edwardjenner"
            };

            var googleSettings = new GoogleSettings
            {
                ApiKey = "AIzaSyA24yDHFfDuszVUomPTe8EiLTIdGjbESYc"
            };

            var googleMapsApi = new GoogleMapsApi(googleSettings);

            var redisConnection = new RedisConnection
            {
                Host    = "127.0.0.1",
                Port    = 6379,
                Seconds = 60000
            };

            var cacheGoogleGeocodeService = new CacheService <GoogleGeocodeResult>(redisConnection);

            _userRepository = new UserRepository(connection, googleMapsApi, cacheGoogleGeocodeService);
        }
Beispiel #5
0
        public GoogleClient(GoogleSettings settings)
        {
            _settings = settings;
            UserCredential credential;

            using (var stream =
                       new FileStream(_settings.PathToCredentials, FileMode.Open, FileAccess.Read))
            {
                var credPath = "token.json";

                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets,
                                                                         Scopes, "user",
                                                                         CancellationToken.None,
                                                                         new FileDataStore(credPath, true))
                             .Result;
                Console.WriteLine("Credential file saved to: " + credPath);
            }

            // Create Google Drive API service.
            _drive = new DriveService(new BaseClientService.Initializer
            {
                HttpClientInitializer = credential, ApplicationName = ApplicationName
            });
            // Create Google Sheets API service.
            _sheets = new SheetsService(new BaseClientService.Initializer
            {
                HttpClientInitializer = credential,
                ApplicationName       = ApplicationName
            });
        }
Beispiel #6
0
 public AuthService(
     IUserService userService,
     IOptions <GoogleSettings> googleSettings,
     IOptions <JWTSettings> jwtSettings)
 {
     _userService    = userService;
     _googleSettings = googleSettings.Value;
     _jwtSettings    = jwtSettings.Value;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 public ContactSyncProfile()
 {
     Name = "Default Contact Profile";
     GoogleSettings = new GoogleSettings();
     ExchangeServerSettings = new ExchangeServerSettings();
     OutlookSettings = new OutlookSettings();
     IsSyncEnabled = true;
     IsDefault = true;
 }
 public CalendarSyncProfile()
 {
     Name = "Default Calendar Profile";
     GoogleSettings = new GoogleSettings();
     SyncSettings = new CalendarSyncSettings();
     ExchangeServerSettings = new ExchangeServerSettings();
     OutlookSettings = new OutlookSettings();
     IsSyncEnabled = true;
     IsDefault = true;
 }
Beispiel #9
0
 public FlickrApi(
     FlickrSettings flickrSettings
     , GoogleSettings googleSettings
     , IMapper <FlickrPhotoDetails, PhotoMetadata> photoDetailMapper
     , IMapper <PagedFlickrPhotos, PagedPhotoSearchResult> photoSearchMapper)
 {
     _flickrSettings    = flickrSettings;
     _googleSettings    = googleSettings;
     _photoDetailMapper = photoDetailMapper;
     _PhotoSearchMapper = photoSearchMapper;
 }
Beispiel #10
0
        protected override void ApplySettings(HydraTaskSettings settings)
        {
            _settings = new GoogleSettings(settings);

            if (settings.IsDefault)
            {
                _settings.DayOffset      = 1;
                _settings.StartFrom      = new DateTime(2000, 1, 1);
                _settings.Interval       = TimeSpan.FromDays(1);
                _settings.IgnoreWeekends = true;
            }
        }
Beispiel #11
0
		protected override void ApplySettings(HydraTaskSettings settings)
		{
			_settings = new GoogleSettings(settings);

			if (settings.IsDefault)
			{
				_settings.DayOffset = 1;
				_settings.StartFrom = new DateTime(2000, 1, 1);
				_settings.Interval = TimeSpan.FromDays(1);
				_settings.IgnoreWeekends = true;
			}
		}
Beispiel #12
0
        private void ConfigureServices()
        {
            _storageServices = new Dictionary <string, IStorageService>();

            foreach (var ss in _hiarcSettings.StorageServices)
            {
                if (ss.Provider == AWS_S3)
                {
                    var settings = new S3Settings
                    {
                        AccessKeyId      = ((dynamic)ss.Config).AccessKeyId,
                        SecretAccessKey  = ((dynamic)ss.Config).SecretAccessKey,
                        RegionSystemName = ((dynamic)ss.Config).RegionSystemName,
                        Bucket           = ((dynamic)ss.Config).Bucket
                    };
                    IOptions <S3Settings> s3Settings = Options.Create(settings);

                    IStorageService s3Service = new S3StorageService(ss.Name, s3Settings, ss.AllowDirectDownload, ss.AllowDirectUpload, _logger);
                    _storageServices.Add(ss.Name, s3Service);
                }
                else if (ss.Provider == AZURE_BLOB_STORAGE)
                {
                    var settings = new AzureSettings
                    {
                        StorageConnectionString = ((dynamic)ss.Config).StorageConnectionString,
                        Container = ((dynamic)ss.Config).Container
                    };

                    IOptions <AzureSettings> azureSettings = Options.Create(settings);

                    IStorageService azureService = new AzureStorageService(ss.Name, azureSettings, ss.AllowDirectDownload, ss.AllowDirectUpload, _logger);
                    _storageServices.Add(ss.Name, azureService);
                }
                else if (ss.Provider == GOOGLE_STORAGE)
                {
                    var settings = new GoogleSettings
                    {
                        ServiceAccountCredential = ((dynamic)ss.Config).ServiceAccountCredential,
                        Bucket = ((dynamic)ss.Config).Bucket
                    };

                    IOptions <GoogleSettings> googleSettings = Options.Create(settings);

                    IStorageService googleService = new GoogleStorageService(ss.Name, googleSettings, ss.AllowDirectDownload, ss.AllowDirectUpload, _logger);
                    _storageServices.Add(ss.Name, googleService);
                }
                else
                {
                    throw new Exception($"Unsupported storage service provider: {ss.Provider}");
                }
            }
        }
Beispiel #13
0
        public GoogleStorageService(string name, IOptions <GoogleSettings> googleSettings, bool allowDirectDownload, bool allowDirectUpload, ILogger <StorageServiceProvider> logger)
        {
            Type                   = StorageServiceProvider.GOOGLE_STORAGE;
            Name                   = name;
            GoogleSettings         = googleSettings.Value;
            SupportsDirectDownload = false;
            AllowDirectDownload    = allowDirectDownload;
            SupportsDirectUpload   = false;
            AllowDirectUpload      = allowDirectUpload;
            _logger                = logger;

            // use a tool like this to escape the Google Service Account Credentials JSON file so you can add it to appsettings.json:
            // https://www.freeformatter.com/json-escape.html
            var sacByteArray = Encoding.UTF8.GetBytes(GoogleSettings.ServiceAccountCredential);
            var sacStream    = new MemoryStream(sacByteArray);
            var credential   = GoogleCredential.FromServiceAccountCredential(ServiceAccountCredential.FromServiceAccountData(sacStream));

            _googleClient = StorageClient.Create(credential);
        }
Beispiel #14
0
 public CommonService(
     ILogger logger,
     IMailSender mailSender,
     IVersionService versionService,
     IConfiguration config,
     IHttpClientFactory clientFactory,
     GoogleSettings googleOptions
     ) : base(logger)
 {
     this.mailSender    = mailSender;
     this.clientFactory = clientFactory;
     this.googleOptions = googleOptions;
     systemInfo         = new SystemInfo()
     {
         Version    = versionService.Get(),
         Name       = config.GetValue <string>("SystemInfo:Name"),
         AdminEmail = OptionsClient.GetData(config.GetValue <string>("SystemInfo:AdminEmail"))
     };
 }
        private static void ConfigureService(IConfiguration configuration, ServiceCollection services)
        {
            services.AddSingleton(configuration);

            IConfigurationSection googleSettingsSection = configuration.GetSection("GoogleSettings");

            services.Configure <GoogleSettings>(googleSettingsSection);
            services.Configure <FileLocations>(configuration.GetSection("FileLocations"));

            services.AddScoped <IAddressBuilder, AddressBuilder>();
            services.AddScoped <IJob, Job>();

            services.AddHttpClient <IGoogleService, GoogleService>()
            .ConfigureHttpClient((provider, client) =>
            {
                var settings = new GoogleSettings();
                googleSettingsSection.Bind(settings);
                client.BaseAddress = new Uri(settings.BaseUrl);
            });
        }
        public GoogleSettings BuildGoogleSettings()
        {
            var googleSettings = new GoogleSettings();

            try
            {
                googleSettings = _configuration.GetSection("Google").Get <GoogleSettings>();
            }
            catch { }

            if (string.IsNullOrWhiteSpace(googleSettings.ApiKey))
            {
                googleSettings = new GoogleSettings
                {
                    ApiKey = Environment.GetEnvironmentVariable("GoogleApiKey")
                };
            }

            return(googleSettings);
        }
Beispiel #17
0
        protected override void OnPreInit(EventArgs e)
        {
            base.OnPreInit(e);

            _settings = _settings.Load();// (SPContext.Current.Site);

            /*
             * try
             * {
             *  Analytics.SetAuthenticationToken(Settings.Current.Token);
             *  Webmastertools.SetAuthenticationToken(Settings.Current.Token);
             * }
             * catch (Exception ex)
             * {
             *  //lbl_error.Text += "Token" + ex.ToString();
             * }
             */

            try
            {
                Analytics.setUserCredentials(Settings.Username, Settings.Password);
                Webmastertools.setUserCredentials(Settings.Username, Settings.Password);
            }
            catch (Exception ex)
            {
                SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data);
                //lbl_error.Text += "Credentials" + ex.ToString();
            }

            /*
             * try
             * {
             *  Analytics.setUserCredentials("*****@*****.**", "557308453");
             *  Webmastertools.setUserCredentials("*****@*****.**", "557308453");
             * }
             * catch (Exception ex)
             * {
             *  //lbl_error.Text += "Credentials" + ex.ToString();
             * }
             */
        }
Beispiel #18
0
        private void ConfigureSettings(IServiceCollection services)
        {
            var corsSettings = new CorsSettings();

            new ConfigureFromConfigurationOptions <CorsSettings>(Configuration.GetSection("CorsSettings")).Configure(corsSettings);
            services.AddSingleton(corsSettings);

            var mongoConnection = new MongoConnection();

            new ConfigureFromConfigurationOptions <MongoConnection>(Configuration.GetSection("MongoConnection")).Configure(mongoConnection);
            services.AddSingleton(mongoConnection);

            var redisConnection = new RedisConnection();

            new ConfigureFromConfigurationOptions <RedisConnection>(Configuration.GetSection("RedisConnection")).Configure(redisConnection);
            services.AddSingleton(redisConnection);

            var googleSettings = new GoogleSettings();

            new ConfigureFromConfigurationOptions <GoogleSettings>(Configuration.GetSection("GoogleSettings")).Configure(googleSettings);
            services.AddSingleton(googleSettings);
        }
        public async Task <IEnumerable <Snippet> > GetSnippetsFromParserAsync(string searchQuery, int count)
        {
            var searchEngine = new Engine(); // обьект поискового движка

            #region Settings for services
            var yandexSettings = new YandexSettings();
            var googleSettings = new GoogleSettings();
            var bingSettings   = new BingSettings();
            #endregion

            #region Helpers
            var yandexHelper = new YandexServiceHelper();
            var googleHelper = new GoogleServiceHelper();
            var bingHelper   = new BingServiceHelper();
            #endregion

            #region Services
            var yandex = new Yandex(yandexSettings, yandexHelper);
            var google = new Google(googleSettings, googleHelper);
            var bing   = new Bing(bingSettings, bingHelper);
            #endregion

            var services = new List <ISearchService>()
            {
                google, yandex, bing
            };

            searchEngine.AddRangeSearchServices(services);

            var snippets = searchEngine.Start(searchQuery, count);

            if (snippets != null)
            {
                await _snippetRepository.AddRangeAsync(snippets);
            }

            return(snippets);
        }
Beispiel #20
0
        public UserService(
            IMapper mapper,
            ILogger logger,
            TextBookerContext db,
            IMailSender mailSender,
            JwtSettings jwtSettings,
            GoogleSettings googleOptions,
            IHttpClientFactory clientFactory,
            IHttpContextAccessor httpContextAccessor
            ) : base(logger)
        {
            this.mapper        = mapper;
            this.db            = db;
            this.mailSender    = mailSender;
            this.jwtSettings   = jwtSettings;
            this.googleOptions = googleOptions;
            this.clientFactory = clientFactory;
            httpContext        = httpContextAccessor.HttpContext;
            baseUrl            = $"{httpContext.Request.Scheme}://{httpContext.Request.Host}{httpContext.Request.PathBase}";

            var hashOptions = new HashingOptions();

            passwordHasher = new PasswordHasher(hashOptions);
        }
 public GoogleService(HttpClient client,
                      IOptions <GoogleSettings> googleSettingsOptions)
 {
     _httpClient     = client;
     _googleSettings = googleSettingsOptions.Value;
 }
 public AnalyticsRibbon(SPPageStateControl psc)
     : base(psc)
 {
     settings = new GoogleSettings();
 }
 public SyncProfile()
 {
     OutlookSettings = new OutlookSettings();
     GoogleSettings  = new GoogleSettings();
 }
 public LocationManager(GoogleSettings googleSettings)
 {
     _googleSettings = googleSettings;
 }
 public GoogleMapsApi([FromServices] GoogleSettings googleSettings)
 {
     _restSharp = new RestSharpCommon("https://maps.googleapis.com");
     _apiKey    = googleSettings.ApiKey;
 }
        public static async Task <Result> RecaptchaTokenVerify(IHttpClientFactory clientFactory, GoogleSettings googleOptions, string token)
        {
            var tokenResponse = new TokenResponseModel()
            {
                Success = false
            };

            using (var client = clientFactory.CreateClient(HttpClientNames.GoogleRecaptcha))
            {
                var response = await client.GetStringAsync($"{googleOptions.RecaptchaVerifyApi}?secret={googleOptions.SecretKey}&response={token}");

                tokenResponse = JsonConvert.DeserializeObject <TokenResponseModel>(response);
            }

            return((!tokenResponse.Success || tokenResponse.Score < (decimal)0.5)
                                 ? Result.Failure("Recaptcha token is invalid")
                                 : Result.Ok());
        }
Beispiel #27
0
 public GoogleController(GoogleSettings googleSettings, ISettingService settingService)
 {
     _googleSettings = googleSettings;
     _settingService = settingService;
 }