Пример #1
0
        public static string CreateMockJWTToken(int authenticationClaimValue)
        {
            JwtSecurityTokenHandler tokenHandler = new JwtSecurityTokenHandler();

            if (!EnvironmentSettingsResolver.TryGetJWTSecretFromEnvironment(out string jwtSecret))
            {
                jwtSecret = AppSettingsResolver.GetSetting <string>("Options:JwtSecret");
            }

            byte[] key = Encoding.ASCII.GetBytes(jwtSecret);

            SecurityTokenDescriptor tokenDescriptor = new SecurityTokenDescriptor
            {
                Subject = new ClaimsIdentity(new Claim[]
                {
                    new Claim(ClaimTypes.NameIdentifier, authenticationClaimValue.ToString())
                }),

                // Changed expiry from original value to reduce active claims for security
                Expires            = DateTime.UtcNow.AddMinutes(5),
                SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
            };
            SecurityToken token = tokenHandler.CreateToken(tokenDescriptor);

            return(tokenHandler.WriteToken(token));
        }
Пример #2
0
        public TestServerHandler()
        {
            MockDBContextInitializer.InitializeDB(getWediumContextOptions());

            _server = new TestServer(new WebHostBuilder()
                                     .UseConfiguration(AppSettingsResolver.InitConfiguration())
                                     .UseStartup <Startup>()
                                     .ConfigureServices(services => {
                services.AddDbContext <WediumContext>(options => options.UseInMemoryDatabase(_guid));
            }));
        }