コード例 #1
0
        private void CreateAuthentication(IServiceCollection services)
        {
            string domain = $"https://{_valueRetrieval.Get("Auth0:Domain")}/";

            services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            }).AddJwtBearer(options =>
            {
                options.Authority = domain;
                options.Audience  = _valueRetrieval.Get("Auth0:ApiIdentifier");
                options.Events    = new JwtBearerEvents
                {
                    OnTokenValidated = context =>
                    {
                        if (context.SecurityToken is JwtSecurityToken token)
                        {
                            if (context.Principal.Identity is ClaimsIdentity identity)
                            {
                                identity.AddClaim(new Claim("access_token", token.RawData));
                            }
                        }

                        return(Task.FromResult(0));
                    }
                };
            });
        }
コード例 #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

            RegisterContainers(services);
            var sp = services.BuildServiceProvider();

            _valueRetrieval = sp.GetService <IGetValue>();

            CreateAuthentication(services);

            services.AddCors(options =>
            {
                options.AddPolicy("AllowAll",
                                  builder =>
                {
                    builder
                    .AllowAnyOrigin()
                    .AllowAnyMethod()
                    .AllowAnyHeader()
                    .AllowCredentials();
                });
            });

            services.AddMvc()
            .AddJsonOptions(x => x.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);


            var connectionString = _valueRetrieval.Get("ConnectionString");

            services.AddDbContext <SongContext>(o => o.UseMySql(connectionString));
        }
コード例 #3
0
        public void RunTask(List <string> wordSplited)
        {
            var count = 20;

            Task[] tasks = new Task[count];
            var    e     = wordSplited.GetEnumerator();

            for (int i = 0; i < count; i++)
            {
                tasks[i] = new Task(() =>
                {
                    while (e.MoveNext())
                    {
                        if (e.Current is string)
                        {
                            _getValue.Get(e.Current);
                        }
                    }
                });
            }
            foreach (var task in tasks)
            {
                task.Start();
            }

            Task.WaitAll(tasks);
        }
コード例 #4
0
        public GoogleSlides(IGetValue valueRetrieval, IFileAndFolderPathsCreator fileAndFolderPathsCreator)
        {
            _fileAndFolderPathsCreator = fileAndFolderPathsCreator;
            _folderForSongs            = valueRetrieval.Get(KeyConfig.FolderForSongs);
            _folderForPptx             = valueRetrieval.Get(KeyConfig.FolderForPptx);
            _folderForZip         = valueRetrieval.Get(KeyConfig.FolderForZip);
            _presentationTemplate = valueRetrieval.Get(KeyConfig.PresentationTemplate);

            var clientSecrets = new ClientSecrets()
            {
                ClientId     = valueRetrieval.Get(KeyConfig.GoogleApiClient),
                ClientSecret = valueRetrieval.Get(KeyConfig.GoogleApiSecret)
            };

            var credPath = valueRetrieval.Get(KeyConfig.GoogleApiToken);

            var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                clientSecrets,
                new[] { DriveService.Scope.Drive, SlidesService.Scope.Presentations },
                "user",
                CancellationToken.None,
                new FileDataStore(credPath, true)).Result;

            _driveService = new DriveService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential
            });
        }
コード例 #5
0
        private UserInfo GetUserInformation()
        {
            // Retrieve the access_token claim which we saved in the OnTokenValidated event
            var accessToken = User.Claims.FirstOrDefault(c => c.Type == "access_token")?.Value;

            // If we have an access_token, then retrieve the user's information
            if (string.IsNullOrEmpty(accessToken))
            {
                return(null);
            }

            var apiClient = new AuthenticationApiClient(_valueRetrieval.Get("Auth0:Domain"));
            var userInfo  = apiClient.GetUserInfoAsync(accessToken);

            userInfo.Wait();
            var user = userInfo.Result;

            return(user);
        }
コード例 #6
0
 public PptxToZipConverter(IFileAndFolderPathsCreator fileAndFolderPath, IGetValue valueRetrieval)
 {
     _fileAndFolderPath = fileAndFolderPath;
     _baseUri           = new Uri(valueRetrieval.Get(KeyConfig.ZamzarUrl));
     _apiKey            = valueRetrieval.Get(KeyConfig.ZamzarKey);
 }
コード例 #7
0
 public FileAndFolderPathsCreator(IGetValue valueRetrieval)
 {
     _valueRetrieval = valueRetrieval;
     _folder         = _valueRetrieval.Get("FileRoot");
     _webAddress     = _valueRetrieval.Get("WebAddress");
 }
コード例 #8
0
        /// <summary>
        /// To lowercase
        /// </summary>
        /// <param name="input">Input</param>
        /// <param name="filter">Filter</param>
        /// <returns>Lowercase input</returns>
        public static byte[] ToLowerCase(byte[] input, IGetValue <double> filter)
        {
            for (int x = input.Length - 1; x >= 0; x--)
            {
                var entry = _cases[input[x]];

                if (entry != null && (filter == null || RandomHelper.IsRandomPercentOk(filter.Get())))
                {
                    input[x] = entry.LowerCase;
                }
            }

            return(input);
        }
コード例 #9
0
ファイル: Account.cs プロジェクト: Jaryn91/Music
 public Account(IGetValue valueRetrieval)
 {
     _baseUri = new Uri(valueRetrieval.Get(KeyConfig.ZamzarUrl));
     _apiKey  = valueRetrieval.Get(KeyConfig.ZamzarKey);
 }