Beispiel #1
0
        private async Task <TokenResponse> GetOrganogramaAccessTokenAsync()
        {
            AutenticacaoIdentityServer autenticacaoIdentityServer = _autenticacaoIdentityServerConfig.Value;

            TokenClient tokenClient = new TokenClient(autenticacaoIdentityServer.Authority + "/connect/token", _clientId, _secret);

            return(await tokenClient.RequestClientCredentialsAsync("siarhes_admin"));
        }
Beispiel #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IOptions <AutenticacaoIdentityServer> autenticacaoIdentityServerConfig)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            app.UseCors("default");

            #region Configurações de autenticação
            JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();

            AutenticacaoIdentityServer autenticacaoIdentityServer = autenticacaoIdentityServerConfig.Value;
            app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
            {
                Authority            = autenticacaoIdentityServer.Authority,
                RequireHttpsMetadata = autenticacaoIdentityServer.RequireHttpsMetadata,

                AllowedScopes         = autenticacaoIdentityServer.AllowedScopes,
                AutomaticAuthenticate = autenticacaoIdentityServer.AutomaticAuthenticate
            });
            #endregion

            #region Configuração para buscar as permissões do usuário
            app.UseRequestUserInfo(new RequestUserInfoOptions
            {
                UserInfoEndpoint = autenticacaoIdentityServer.Authority + "connect/userinfo"
            });
            #endregion

            app.UseMvc();

            // Enable middleware to serve generated Swagger as a JSON endpoint
            app.UseSwagger();

            var requestPath = Environment.GetEnvironmentVariable("REQUEST_PATH") ?? string.Empty;
            // Enable middleware to serve swagger-ui assets (HTML, JS, CSS etc.)
            app.UseSwaggerUi("api/documentation", requestPath + "/swagger/v1/swagger.json");
        }
Beispiel #3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IOptions <AutenticacaoIdentityServer> autenticacaoIdentityServerConfig)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationScheme = "Cookies",

                AutomaticAuthenticate = true,

                ExpireTimeSpan = TimeSpan.FromMinutes(60),
                CookieName     = "OrganogramaJobScheduler.Auth",

                CookiePath = $"{Environment.GetEnvironmentVariable("REQUEST_PATH")}/"
            });

            JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
            AutenticacaoIdentityServer autenticacaoIdentityServer = autenticacaoIdentityServerConfig.Value;
            OpenIdConnectOptions       oico = new OpenIdConnectOptions {
                AuthenticationScheme = "oidc",
                SignInScheme         = "Cookies",

                Authority            = autenticacaoIdentityServer.Authority,
                RequireHttpsMetadata = autenticacaoIdentityServer.RequireHttpsMetadata,

                ClientId     = Environment.GetEnvironmentVariable("OrganogramaJobSchedulerClientId"),
                ClientSecret = Environment.GetEnvironmentVariable("OrganogramaJobSchedulerSecret"),

                ResponseType = "code id_token",
                GetClaimsFromUserInfoEndpoint = true,

                SaveTokens = true,

                TokenValidationParameters = new TokenValidationParameters
                {
                    NameClaimType = "nome",
                    RoleClaimType = "role",
                }
            };

            foreach (string scope in autenticacaoIdentityServer.AllowedScopes)
            {
                oico.Scope.Add(scope);
            }

            app.UseOpenIdConnectAuthentication(oico);

            #region Hangfire
            app.UseHangfireDashboard("/restrito", new DashboardOptions {
                AppPath = $"{Environment.GetEnvironmentVariable("REQUEST_PATH")}/", Authorization = new[] { new HangfireAuthorizationFilter(), }
            });
            app.UseHangfireServer();
            app.UseHangfire();
            #endregion

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }