public async Task InteropWithNewCookieContainsIdentity() { var user = new ClaimsPrincipal(); var identity = new ClaimsIdentity("scheme"); identity.AddClaim(new Claim(ClaimTypes.Name, "Alice")); user.AddIdentity(identity); var dataProtection = new DataProtection.DataProtectionProvider(new DirectoryInfo("..\\..\\artifacts")); var newServer = TestHost.TestServer.Create(app => { app.UseCookieAuthentication(options => options.DataProtectionProvider = dataProtection); app.Run(context => context.Authentication.SignInAsync("Cookies", user)); }, services => services.AddAuthentication()); var cookie = await SendAndGetCookie(newServer, "http://example.com/login"); var server = TestServer.Create(app => { app.Properties["host.AppName"] = "Microsoft.Owin.Security.Tests"; app.UseCookieAuthentication(new CookieAuthenticationOptions(), dataProtection); app.Run(async context => { var result = await context.Authentication.AuthenticateAsync("Cookies"); Describe(context.Response, result); }); }); var transaction2 = await SendAsync(server, "http://example.com/me/Cookies", cookie); Assert.Equal("Alice", FindClaimValue(transaction2, ClaimTypes.Name)); }
public async Task AspNet5WithInteropCookieContainsIdentity() { var identity = new ClaimsIdentity("Cookies"); identity.AddClaim(new Claim(ClaimTypes.Name, "Alice")); var dataProtection = new DataProtection.DataProtectionProvider(new DirectoryInfo("..\\..\\artifacts")); var interopServer = TestServer.Create(app => { app.Properties["host.AppName"] = "Microsoft.Owin.Security.Tests"; app.UseCookieAuthentication(new CookieAuthenticationOptions(), dataProtection); app.Run(context => { context.Authentication.SignIn(identity); return(Task.FromResult(0)); }); }); var transaction = await SendAsync(interopServer, "http://example.com"); var newServer = TestHost.TestServer.Create(app => { app.UseCookieAuthentication(options => options.DataProtectionProvider = dataProtection); app.Run(async context => { var result = await context.Authentication.AuthenticateAsync("Cookies"); await context.Response.WriteAsync(result.Identity.Name); }); }, services => services.AddAuthentication()); var request = new HttpRequestMessage(HttpMethod.Get, "http://example.com/login"); request.Headers.Add("Cookie", transaction.SetCookie.Split(new[] { ';' }, 2).First()); var response = await newServer.CreateClient().SendAsync(request); Assert.Equal("Alice", await response.Content.ReadAsStringAsync()); }
public async Task InteropWithNewCookieContainsIdentity() { var user = new ClaimsPrincipal(); var identity = new ClaimsIdentity("scheme"); identity.AddClaim(new Claim(ClaimTypes.Name, "Alice")); user.AddIdentity(identity); var dataProtection = new DataProtection.DataProtectionProvider(new DirectoryInfo("..\\..\\artifacts")); var newServer = TestHost.TestServer.Create(app => { app.UseCookieAuthentication(options => options.DataProtectionProvider = dataProtection); app.Run(context => context.Authentication.SignInAsync("Cookies", user)); }, services => services.AddAuthentication()); var cookie = await SendAndGetCookie(newServer, "http://example.com/login"); var server = TestServer.Create(app => { app.Properties["host.AppName"] = "Microsoft.Owin.Security.Tests"; app.UseCookieAuthentication(new CookieAuthenticationOptions(), dataProtection); app.Run(async context => { var result = await context.Authentication.AuthenticateAsync("Cookies"); Describe(context.Response, result); }); }); var transaction2 = await SendAsync(server, "http://example.com/me/Cookies", cookie); Assert.Equal("Alice", FindClaimValue(transaction2, ClaimTypes.Name)); }
public async Task AspNet5WithInteropCookieContainsIdentity() { var identity = new ClaimsIdentity("Cookies"); identity.AddClaim(new Claim(ClaimTypes.Name, "Alice")); var dataProtection = new DataProtection.DataProtectionProvider(new DirectoryInfo("..\\..\\artifacts")); var interopServer = TestServer.Create(app => { app.Properties["host.AppName"] = "Microsoft.Owin.Security.Tests"; app.UseCookieAuthentication(new CookieAuthenticationOptions(), dataProtection); app.Run(context => { context.Authentication.SignIn(identity); return Task.FromResult(0); }); }); var transaction = await SendAsync(interopServer, "http://example.com"); var newServer = TestHost.TestServer.Create(app => { app.UseCookieAuthentication(options => options.DataProtectionProvider = dataProtection); app.Run(async context => { var result = await context.Authentication.AuthenticateAsync("Cookies"); await context.Response.WriteAsync(result.Identity.Name); }); }, services => services.AddAuthentication()); var request = new HttpRequestMessage(HttpMethod.Get, "http://example.com/login"); request.Headers.Add("Cookie", transaction.SetCookie.Split(new[] { ';' }, 2).First()); var response = await newServer.CreateClient().SendAsync(request); Assert.Equal("Alice", await response.Content.ReadAsStringAsync()); }