private static ComputerVisionClient CreateComputerVisionClient(AzureAIOptions options)
        {
            ComputerVisionClient computerVision = new ComputerVisionClient(
                new ApiKeyServiceClientCredentials(options.SubscriptionKey),
                new DelegatingHandler[] { });

            computerVision.Endpoint = options.Endpoint;

            return(computerVision);
        }
        public static IMagicMediaServerBuilder AddAzureAI(
            this IMagicMediaServerBuilder builder)
        {
            AzureAIOptions options = builder.Configuration
                                     .GetSection("MagicMedia:AzureAI")
                                     .Get <AzureAIOptions>();

            builder.Services.AddAzureAI(options);

            return(builder);
        }
        private static IServiceCollection AddAzureAI(
            this IServiceCollection services,
            AzureAIOptions options)
        {
            services.AddSingleton <ICloudAIMediaAnalyser, AzureComputerVision>();
            Func <ComputerVisionClient> factory = () => CreateComputerVisionClient(options);

            services.AddSingleton(factory);

            return(services);
        }
示例#4
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews()
            .AddRazorRuntimeCompilation();

            services.Configure <ForwardedHeadersOptions>(options =>
            {
                options.ForwardedHeaders =
                    ForwardedHeaders.XForwardedFor |
                    ForwardedHeaders.XForwardedProto;
            });

            JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();

            services.AddAuthentication(options =>
            {
                options.DefaultScheme          = CookieAuthenticationDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme = "oidc";
            })
            .AddCookie(options =>
            {
                options.ExpireTimeSpan = TimeSpan.FromMinutes(60);
                options.Cookie.Name    = "media-sample";
            })
            .AddOpenIdConnect("oidc", options =>
            {
                options.Authority            = "http://localhost:5500";
                options.RequireHttpsMetadata = false;

                options.ClientSecret = "geCDNACu94a5DfZQ2Sm46DBjkSErAnNA";
                options.ClientId     = "Media.UI";
                options.ResponseType = "code";

                options.Scope.Clear();
                options.Scope.Add("openid");
                options.Scope.Add("profile");

                options.ClaimActions.MapAllExcept("iss", "nbf", "exp", "aud", "nonce", "iat", "c_hash");

                options.SaveTokens = true;
                options.Events     = new OpenIdConnectEvents
                {
                    OnRedirectToIdentityProvider = (ctx) =>
                    {
                        return(Task.CompletedTask);
                    },
                    OnTicketReceived = (ctx) =>
                    {
                        return(Task.CompletedTask);
                    }
                };

                options.TokenValidationParameters = new TokenValidationParameters
                {
                    NameClaimType = JwtClaimTypes.Name,
                    RoleClaimType = JwtClaimTypes.Role,
                };
            });

            services.Configure <CookiePolicyOptions>(options =>
            {
                options.MinimumSameSitePolicy = SameSiteMode.Unspecified;
                options.OnAppendCookie        = cookieContext =>
                                                CheckSameSite(cookieContext.Context, cookieContext.CookieOptions);
                options.OnDeleteCookie = cookieContext =>
                                         CheckSameSite(cookieContext.Context, cookieContext.CookieOptions);
            });

            services.AddCoreMediaServices(Configuration);
            services.AddFaceDetection(Configuration);
            BingMapsOptions bingOptions = Configuration.GetSection("MagicMedia:BingMaps")
                                          .Get <BingMapsOptions>();

            services.AddFileSystemStore(Configuration);

            //services.AddBingMaps(bingOptions);

            services.AddMongoDbStore(Configuration);

            services.AddSingleton <SampleService>();

            AzureAIOptions azureAi = Configuration.GetSection("MagicMedia:AzureAI")
                                     .Get <AzureAIOptions>();

            services.AddAzureAI(azureAi);
        }