public async Task CreateAsync(AuthenticationTokenCreateContext context) { var clientid = context.Ticket.Properties.Dictionary[clientPropertyKey]; if (string.IsNullOrEmpty(clientid)) { return; } var refreshTokenId = Guid.NewGuid().ToString("n"); var refreshTokenLifeTime = context.OwinContext.Get <string>("as:clientRefreshTokenLifeTime"); var token = new RefreshToken() { Id = HashMaker.GetHash(refreshTokenId), ClientId = clientid, Subject = context.Ticket.Identity.Name, IssuedUtc = DateTime.UtcNow, ExpiresUtc = DateTime.UtcNow.AddMinutes(Convert.ToDouble(refreshTokenLifeTime)) }; context.Ticket.Properties.IssuedUtc = token.IssuedUtc; context.Ticket.Properties.ExpiresUtc = token.ExpiresUtc; token.ProtectedTicket = context.SerializeTicket(); var result = await authRepository.AddRefreshToken(token); if (result) { context.SetToken(refreshTokenId); } }
protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); builder.Entity <User>().ToTable("Users"); builder.Entity <User>().HasKey(p => p.Id); builder.Entity <User>().Property(p => p.Email).IsRequired(); builder.Entity <User>().Property(p => p.Phone).IsRequired(); builder.Entity <User>().Property(p => p.GivenName).IsRequired(); builder.Entity <User>().Property(p => p.Surname).IsRequired(); builder.Entity <User>().Property(p => p.PasswordHash).IsRequired(); builder.Entity <User>().Property(p => p.MiddleName); builder.Entity <User>().HasMany(p => p.Files).WithOne(p => p.Owner).HasForeignKey(p => p.OwnerID); builder.Entity <User>().HasData( new User { Id = Guid.NewGuid(), GivenName = "Egor", Surname = "Solodaev", MiddleName = "", Email = "*****@*****.**", Phone = "+13371488", PasswordHash = HashMaker.GetHash("mypassword") } ); builder.Entity <FileRecord>().ToTable("Files"); builder.Entity <FileRecord>().HasKey(p => p.Id); builder.Entity <FileRecord>().Property(p => p.Id).IsRequired().ValueGeneratedOnAdd(); builder.Entity <FileRecord>().Property(p => p.Name).IsRequired(); builder.Entity <FileRecord>().Property(p => p.Path).IsRequired(); }
public async Task ReceiveAsync(AuthenticationTokenReceiveContext context) { var allowedOrigin = context.OwinContext.Get <string>("as:clientAllowedOrigin"); context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin }); var hashedTokenId = HashMaker.GetHash(context.Token); var refreshToken = await authRepository.FindRefreshToken(hashedTokenId); if (refreshToken != null) { // Get protectedTicket from refreshToken class context.DeserializeTicket(refreshToken.ProtectedTicket); var result = await authRepository.RemoveRefreshToken(hashedTokenId); } }