Пример #1
0
        private void btnValidate_Click(object sender, EventArgs e)
        {
            VALIDATIONSTATE state;

            jwt   = new JWTAuthentication(txtSecretKey.Text);
            state = jwt.ValidationToken(txtToken.Text);

            txtHeader.Text  = jwt.HeaderJson;
            txtPayload.Text = jwt.PayloadJson;

            lblValidateState.Text = string.Format("Validation State: {0}", state);
        }
Пример #2
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            UserInfo user = new UserInfo();

            user.Id        = Guid.Parse(txtId.Text);
            user.Email     = txtEmail.Text;
            user.FirstName = txtFirstName.Text;
            user.LastName  = txtLastName.Text;

            jwt           = new JWTAuthentication(txtSecretKey.Text);
            txtToken.Text = jwt.CreateToken(user, HSMODE.HS512);
        }
Пример #3
0
        public async Task <IActionResult> Authenticate([FromBody] UserAuthenticateModel userModel)
        {
            var userDetails = await _userService.Authenticate(userModel);

            string tokenString = JWTAuthentication.GetToken(userDetails, _appSettings.Secret);

            // return basic user info (without password) and token to store client side
            return(Ok(new
            {
                userid = userDetails.UserId,
                token = tokenString
            }));
        }
Пример #4
0
        private void btnParse_Click(object sender, EventArgs e)
        {
            UserInfo user;

            jwt  = new JWTAuthentication(txtSecretKey.Text);
            user = jwt.ParseToken <UserInfo>(txtToken.Text);

            txtId.Text        = user.Id.ToString();
            txtEmail.Text     = user.Email;
            txtFirstName.Text = user.FirstName;
            txtLastName.Text  = user.LastName;

            txtHeader.Text  = jwt.HeaderJson;
            txtPayload.Text = jwt.PayloadJson;
        }
Пример #5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors();
            //services.AddDbContext<DataContext>(x => x.UseInMemoryDatabase("TestDb"));
            services.AddMvc(opt =>
            {
                opt.Filters.Add(typeof(ValidatorActionFilter));
            }).AddFluentValidation(fvc => {
                fvc.RegisterValidatorsFromAssemblyContaining <Startup>();
                fvc.ImplicitlyValidateChildProperties = true;
            });

            services.AddAutoMapper();

            // configure strongly typed settings objects
            var appSettingsSection = Configuration.GetSection("AppSettings");

            services.Configure <AppSettings>(appSettingsSection);

            // configure jwt authentication
            JWTAuthentication.Configure(services, appSettingsSection.Get <AppSettings>().Secret);

            // Register the Swagger generator, defining 1 or more Swagger documents
            AddSwaggerGen(services);

            //Register DB Context
            var dbConnectionString = appSettingsSection.Get <AppSettings>().DBConnectionString;

            services.AddDbContext <DataContext>(options => options.UseSqlServer(dbConnectionString));

            // configure DI for application services
            services.AddScoped <OperatingUser, OperatingUser>();
            services.AddScoped <IUserService, UserService>();
            services.AddScoped <IRoleService, RoleService>();
            services.AddScoped <IUserTypeService, UserTypeService>();
            services.AddScoped <IContentService, ContentService>();
            services.AddScoped <IUserContentService, UserContentService>();
        }