示例#1
0
        public async Task <string> GenerateJwtToken(DeliveryAccount account)
        {
            var claims = new List <Claim>
            {
                new Claim(JwtRegisteredClaimNames.Sub, account.MobileUserId),
                new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
                new Claim(ClaimTypes.NameIdentifier, account.Id),
                new Claim(CustomClaimType.CourtId, account.CourtId.ToString()),
                new Claim(CustomClaimType.LawUnitId, account.LawUnitId.ToString()),
            };

            var key   = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(configuration["JwtKey"]));
            var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
            //var expires = DateTime.Now.AddDays(Convert.ToDouble(configuration["JwtExpireDays"]));
            var expires = DateTime.Now.AddMinutes(Convert.ToDouble(configuration["JwtExpireMinutes"]));


            var token = new JwtSecurityToken(
                configuration["JwtIssuer"],
                configuration["JwtIssuer"],
                claims,
                expires: expires,
                signingCredentials: creds
                );

            return(new JwtSecurityTokenHandler().WriteToken(token));
        }
示例#2
0
        private async Task <string> GenerateJwtMobileToken(DeliveryAccount account)
        {
            var claims = new List <Claim>
            {
                new Claim(JwtRegisteredClaimNames.Sub, account.MobileUserId),
                new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
                new Claim(ClaimTypes.NameIdentifier, account.Id),
                new Claim(CustomClaimType.CourtId, account.CourtId.ToString()),
                new Claim(CustomClaimType.LawUnitId, account.LawUnitId.ToString()),
            };

            // var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(configuration["JwtMobileKey"]));
            //  var creds = new SigningCredentials(key, SecurityAlgorithms.EcdsaSha256); // .EcdsaSha512); // HmacSha256);
            string privateKey = configuration["JwtMobileKey"];
            ECDsa  eCDsa      = EDCsaHelper.LoadPrivateKey(EDCsaHelper.FromHexString(privateKey));
            var    key        = new ECDsaSecurityKey(eCDsa);
            var    creds      = new SigningCredentials(key, SecurityAlgorithms.EcdsaSha512); // .EcdsaSha512); // HmacSha256);
            var    expires    = DateTime.Now.AddDays(Convert.ToDouble(configuration["JwtMobileExpireDays"]));

            var token = new JwtSecurityToken(
                configuration["JwtMobileIssuer"],
                configuration["JwtMobileIssuer"],
                claims,
                expires: expires,
                signingCredentials: creds
                );

            return(new JwtSecurityTokenHandler().WriteToken(token));
        }
示例#3
0
        public (string, string) GenerateBarcodeTying(string userId)
        {
            string mobileApiAddr = configuration["MobileApiURI"];
            var    user          = repo.All <ApplicationUser>()
                                   .Where(x => x.Id == userId)
                                   .FirstOrDefault();

            if (user == null)
            {
                return(null, null);
            }
            string newId   = Guid.NewGuid().ToString();
            var    account = new DeliveryAccount()
            {
                Id           = newId,
                ApiAddress   = mobileApiAddr + newId,
                CourtId      = user.CourtId,
                LawUnitId    = user.LawUnitId,
                IsActive     = true,
                MobileUserId = user.Id,
                MobileToken  = "",
                PinHash      = "",
                UserId       = userContext.UserId,
                DateWrt      = DateTime.Now
            };

            repo.Add(account);
            repo.SaveChanges();

            return(account.ApiAddress, GenerateBarcode(account.ApiAddress));
        }