Exemplo n.º 1
0
 public AuthController(UserManager <ApplicationUser> userManager, IOptions <JwtBearerTokenSettings> jwtTokenOptions, IEmailService emailService, IMapper mapper)
 {
     this.mapper                 = mapper;
     this.emailService           = emailService;
     this.userManager            = userManager;
     this.jwtBearerTokenSettings = jwtTokenOptions.Value;
 }
Exemplo n.º 2
0
 public AuthController(IOptions <JwtBearerTokenSettings> jwtTokenOptions, UserManager <User> userManager, RoleManager <IdentityRole> roleManager, RefreshTokenRepository refreshTokenRepository)
 {
     this.jwtBearerTokenSettings = jwtTokenOptions.Value;
     this.userManager            = userManager;
     this.roleManager            = roleManager;
     this.refreshTokenRepository = refreshTokenRepository;
 }
Exemplo n.º 3
0
 public AuthController(IOptions <JwtBearerTokenSettings> jwtTokenOptions, UserManager <IdentityUser> userManager, RoleManager <IdentityRole> roleManager, ApplicationDbContext dbContext)
 {
     this.jwtBearerTokenSettings = jwtTokenOptions.Value;
     this.userManager            = userManager;
     this.roleManager            = roleManager;
     this._dbContext             = dbContext;
 }
Exemplo n.º 4
0
 public AuthController(IOptions <JwtBearerTokenSettings> jwtBearerTokenSettings, UserManager <User> userManager, RoleManager <IdentityRole> roleManager, IMapper mapper)
 {
     _jwtBearerTokenSettings = jwtBearerTokenSettings.Value;
     _userManager            = userManager;
     _roleManager            = roleManager;
     _mapper = mapper;
 }
Exemplo n.º 5
0
 public UserController(UserManager <AppUser> userManager, SignInManager <AppUser> signInManager, RoleManager <IdentityRole> roleManager, IOptions <JwtBearerTokenSettings> jwtTokenOptions, ILogger <UserController> logger)
 {
     this.userManager            = userManager;
     this.signInManager          = signInManager;
     this.roleManager            = roleManager;
     this.logger                 = logger;
     this.jwtBearerTokenSettings = jwtTokenOptions.Value;
 }
Exemplo n.º 6
0
 public AuthenticationService(
     IOptions <JwtBearerTokenSettings> jwtTokenOptions,
     UserManager <ApplicationUser> userManager,
     IMapper mapper)
 {
     _jwtBearerTokenSettings = jwtTokenOptions.Value;
     _userManager            = userManager;
     _mapper = mapper;
 }
Exemplo n.º 7
0
 public AuthController(
     IOptions <JwtBearerTokenSettings> jwtTokenOptions,
     IUserService userService,
     UserManager <IdentityUser> userManager)
 {
     _userService            = userService;
     _jwtBearerTokenSettings = jwtTokenOptions.Value;
     _userManager            = userManager;
 }
Exemplo n.º 8
0
        public static void ConfigureIdentity(this IServiceCollection services, JwtBearerTokenSettings jwtSettings, bool isDevelopment)
        {
            services.AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultScheme             = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(options =>
            {
                if (isDevelopment)
                {
                    options.RequireHttpsMetadata = false;
                }

                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ClockSkew                = TimeSpan.FromMinutes(2),
                    IssuerSigningKey         = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(jwtSettings.SecretKey)),
                    RequireExpirationTime    = true,
                    RequireSignedTokens      = true,
                    ValidateIssuerSigningKey = true,
                    ValidateIssuer           = true,
                    ValidateAudience         = false,
                    ValidateLifetime         = true,
                    NameClaimType            = "name",
                    RoleClaimType            = "role",
                    ValidIssuer              = jwtSettings.Issuer,
                    ValidAudience            = jwtSettings.Audience
                };

                options.Events = new JwtBearerEvents
                {
                    OnAuthenticationFailed = context =>
                    {
                        if (context.Exception.GetType() == typeof(SecurityTokenExpiredException))
                        {
                            context.Response.Headers.Add("Token-Expired", "true");
                        }
                        else
                        {
                            context.Response.Headers.Add("Token-Error", context.Exception.Message);
                        }
                        return(Task.CompletedTask);
                    },
                    OnTokenValidated = context =>
                    {
                        return(Task.CompletedTask);
                    }
                };
            });
        }
 public AuthService(
     UserManager <DbUser> userManager,
     SignInManager <DbUser> signInManager,
     EmailService emailService,
     AppDbContext context,
     IOptions <JwtBearerTokenSettings> jwtBearerTokenOptions)
 {
     this.userManager       = userManager;
     this.signInManager     = signInManager;
     this.emailService      = emailService;
     this.context           = context;
     jwtBearerTokenSettings = jwtBearerTokenOptions.Value;
 }
Exemplo n.º 10
0
        private string GenerateToken(IdentityUser identityUser, JwtBearerTokenSettings jwtBearerTokenSettings)
        {
            var tokenHandler    = new JwtSecurityTokenHandler();
            var key             = Encoding.ASCII.GetBytes(jwtBearerTokenSettings.SecretKey);
            var tokenDescriptor = new SecurityTokenDescriptor
            {
                Subject            = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, identityUser.UserName), new Claim(ClaimTypes.Email, identityUser.Email) }),
                Expires            = DateTime.UtcNow.AddSeconds(jwtBearerTokenSettings.ExpiryTimeInSeconds),
                SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature),
                Audience           = jwtBearerTokenSettings.Audience,
                Issuer             = jwtBearerTokenSettings.Issuer
            };
            var securityToken = tokenHandler.CreateToken(tokenDescriptor);
            var token         = tokenHandler.WriteToken(securityToken);

            return(token);
        }
Exemplo n.º 11
0
 public AuthController(IOptions <JwtBearerTokenSettings> jwtTokenOptions,
                       UserManager <User> userManager,
                       RepositoryContext dbContext,
                       ILogger <AuthController> logger,
                       IHubContext <NotifHub> hubContext,
                       RoleManager <Role> roleManager,
                       IUserConnectionManager userConnectionManager,
                       IMapper mapper)
 {
     _jwtBearerTokenSettings = jwtTokenOptions.Value;
     _userManager            = userManager;
     _dbContext             = dbContext;
     _userConnectionManager = userConnectionManager;
     _roleManager           = roleManager;
     _mapper     = mapper;
     _logger     = logger;
     _hubContext = hubContext;
 }
Exemplo n.º 12
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors(options =>
            {
                options.AddPolicy("localhost",
                                  builder =>
                {
                    builder.WithOrigins("https://localhost:4200", "http://localhost:4200");
                    builder.AllowAnyMethod();
                    builder.AllowAnyHeader();
                });
            });

            services.AddControllers();

            IConfigurationSection  jwtSection             = Configuration.GetSection("JwtBearerTokenSettings");
            JwtBearerTokenSettings jwtBearerTokenSettings = jwtSection.Get <JwtBearerTokenSettings>();

            services.AddSingleton <ITokenService, TokenService>(sp => new TokenService(jwtSection.Get <JwtBearerTokenSettings>().SecretKey));

            IConfigurationSection dbSection            = Configuration.GetSection("DbConnectionSettings");
            DbConnectionSettings  dbConnectionSettings = dbSection.Get <DbConnectionSettings>();
            string connectionString = dbSection.Get <DbConnectionSettings>().SqlServerConnectionString;

            services.AddSingleton <DbProviderFactory>(sp => SqlClientFactory.Instance);
            services.AddSingleton(sp => new ConnectionInfo(connectionString));
            services.AddSingleton <Connection>();

            services.AddSingleton <AuthService>();
            services.AddSingleton <UserService>();
            services.AddSingleton <RoleService>();
            services.AddSingleton <GameService>();
            services.AddSingleton <RuleService>();
            services.AddSingleton <TimeControlService>();
            services.AddSingleton <StatisticService>();
        }
Exemplo n.º 13
0
 public AuthController(IOptions <JwtBearerTokenSettings> jwtTokenOptions,
                       UserManager <User> userManager)
 {
     _userManager            = userManager;
     _jwtBearerTokenSettings = jwtTokenOptions.Value;
 }
Exemplo n.º 14
0
 public AuthController(IOptions <JwtBearerTokenSettings> jwtTokenOptions, UserManager <IdentityUser> userManager)
 {
     this.jwtBearerTokenSettings = jwtTokenOptions.Value;
     this.userManager            = userManager;
 }
Exemplo n.º 15
0
 public JwtService(IOptions <JwtBearerTokenSettings> jwtBearerTokenSettings)
 {
     _jwtBearerTokenSettings = jwtBearerTokenSettings.Value;
 }
Exemplo n.º 16
0
 public AuthController(IOptions <JwtBearerTokenSettings> jwtTokenOptions, UserManager <ApplicationUser> userManager, ApplicationDbContext dbContext)
 {
     this.jwtBearerTokenSettings = jwtTokenOptions.Value;
     this.userManager            = userManager;
     this.dbContext = dbContext;
 }
 public AccountController(IOptions <JwtBearerTokenSettings> jwtTokenOptions, UserManager <AppUser> userManager, SignInManager <AppUser> signInManager)
 {
     this.jwtBearerTokenSettings = jwtTokenOptions.Value;
     _signInManager = signInManager;
     _userManager   = userManager;
 }
Exemplo n.º 18
0
 public LoginController(IOptions <JwtBearerTokenSettings> jwtTokenOptions, UserManager <IdentityUser> userManager, UnitOfWork unitOfWork)
 {
     this.unitOfWork             = unitOfWork;
     this.userManager            = userManager;
     this.jwtBearerTokenSettings = jwtTokenOptions.Value;
 }