Exemplo n.º 1
0
        private void SetAuthCookie(HttpContext httpContext, string userName)
        {
            //TODO add identity

            ContextIdentity identity = new ContextIdentity();

            identity.UserName = userName;

            var roles = new string[] { "User" };

            GenericPrincipal genericPrincipal = new GenericPrincipal(identity, roles);

            httpContext.User = genericPrincipal;

            HttpCookie cookie = new HttpCookie("isUserAuthorized");

            cookie.Value   = "true";
            cookie.Expires = DateTime.Now.AddMinutes(10);

            httpContext.Response.SetCookie(cookie);

            httpContext.Response.SetCookie(new HttpCookie("userId")
            {
                Value = userName
            });
        }
Exemplo n.º 2
0
 public static IApplicationBuilder UseConfiguracaoIdentity(this IApplicationBuilder app, ContextIdentity contextIdentity)
 {
     //usar em banco de dados relacional e que nao seja em memoria
     contextIdentity.Database.Migrate();
     return(app);
 }
Exemplo n.º 3
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ContextEntity contextEntity, ContextIdentity contextIdentity, ContextMongo contextMongo)
        {
            app.UseConfiguracaoEntity(contextEntity);

            app.UseConfiguracaoIdentity(contextIdentity);

            app.UseConfiguracaoMongo(contextMongo, contextEntity);

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseMiddleware <ExceptionMiddlware>();

            app.UseCors("CorsOptions");

            //app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthConfiguration();

            app.UseAuthentication();

            app.UseAuthorization();

            app.UseHealthChecksUI(SetOptionsHeathCheck);
            app.UseHealthChecks("/check", new HealthCheckOptions()
            {
                Predicate      = _ => true,
                ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse,
            });

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Exemplo n.º 4
0
 public StudentController(ContextIdentity context, UserManager <User> userManager)
 {
     db           = context;
     _userManager = userManager;
 }
 public UsuarioClaimsPrincipalFactory(UserManager <Usuario> userManager, IOptions <IdentityOptions> optionsAccessor, ContextIdentity contextIdentity, IContaRepository contaRepository) : base(userManager, optionsAccessor)
 {
     _contextIdentity = contextIdentity;
     _contaRepository = contaRepository;
 }