public UserService(IIdentityUnitOfWork uow, IMapper mapper, IJwtFactory jwtFactory, JWTIssuerOptions jwtOptions, IHttpContextAccessor httpContextAccessor)
 {
     db                       = uow;
     this.mapper              = mapper;
     this.jwtFactory          = jwtFactory;
     this.jwtOptions          = jwtOptions;
     this.httpContextAccessor = httpContextAccessor;
 }
 public AccountController(UserManager <AppUser> userManager, IMapper mapper, TodoContext appDbContext,
                          IJwtFactory jwtFactory, IOptions <JWTIssuerOptions> jwtOptions)
 {
     _userManager  = userManager;
     _mapper       = mapper;
     _appDbContext = appDbContext;
     _jwtFactory   = jwtFactory;
     _jwtOptions   = jwtOptions.Value;
 }
 public AccountController(UserManager <UniversityUserModel> userManager, IJWTFactory jwtFactory,
                          IOptions <JWTIssuerOptions> jwtOptions, BLLUnitOfWork bll, IConfigurationRoot config)
 {
     _userManager = userManager;
     _jwtFactory  = jwtFactory;
     _jwtOptions  = jwtOptions.Value;
     _bll         = bll;
     _config      = config;
 }
Example #4
0
        private readonly JsonSerializerSettings _serializerSettings; // To serialize data in JSON format. Newtonsoft

        public AccountManager(UserManager <AppUser> usermanager, IJWFactory jwtFactory, IOptions <JWTIssuerOptions> jwtOptions)
        {
            _userManager = usermanager;
            _jwtFactory  = jwtFactory;
            _jwtOptions  = jwtOptions.Value;

            _serializerSettings = new JsonSerializerSettings
            {
                Formatting = Formatting.Indented
            };
        }
Example #5
0
        private static void ThrowIfInvalidOptions(JWTIssuerOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (options.ValidFor <= TimeSpan.Zero)
            {
                throw new ArgumentException("Must be a non-zero TimeSpan.", nameof(JWTIssuerOptions.ValidFor));
            }

            if (options.SigningCredentials == null)
            {
                throw new ArgumentNullException(nameof(JWTIssuerOptions.SigningCredentials));
            }

            if (options.JtiGenerator == null)
            {
                throw new ArgumentNullException(nameof(JWTIssuerOptions.JtiGenerator));
            }
        }
Example #6
0
 public JwtFactory(IOptions <JWTIssuerOptions> jwtOptions)
 {
     _jwtOptions = jwtOptions.Value;
     ThrowIfInvalidOptions(_jwtOptions);
 }
 public JWTFactory(UserManager <UniversityUserModel> userManager, IOptions <JWTIssuerOptions> jwtOptions)
 {
     _jwtOptions  = jwtOptions.Value;
     _userManager = userManager;
 }
Example #8
0
 public JwtFactory(IOptions <JWTIssuerOptions> jwtOptions, IIdentityUnitOfWork db)
 {
     this.jwtOptions = jwtOptions.Value;
     this.db         = db;
     ThrowIfInvalidOptions(this.jwtOptions);
 }
Example #9
0
        public static async Task <string> GenerateJwt(ClaimsIdentity claimsIdentity, IJwtFactory jwtFactory, IdentityUser user, JWTIssuerOptions jwtOptions, JsonSerializerSettings serializerSettings)
        {
            var response = new
            {
                id         = claimsIdentity.Claims.Single(c => c.Type == "id").Value,
                auth_token = await jwtFactory.GenerateEncodedToken(user, claimsIdentity),
                expires_in = (int)jwtOptions.ValidFor.TotalSeconds
            };

            return(JsonConvert.SerializeObject(response, serializerSettings));
        }