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
            });
        }
Exemple #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);
 }
        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();
            });
        }
Exemple #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;
 }