Reacting to new Hosting API
This commit is contained in:
parent
cade3de890
commit
4f577e7217
|
|
@ -1,3 +1,3 @@
|
||||||
{
|
{
|
||||||
"projects": ["src", "C:\\Github\\Options\\src"]
|
"projects": ["src"]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ using System.IO;
|
||||||
using IdentitySample.Models;
|
using IdentitySample.Models;
|
||||||
using Microsoft.AspNet.Builder;
|
using Microsoft.AspNet.Builder;
|
||||||
using Microsoft.AspNet.DataProtection;
|
using Microsoft.AspNet.DataProtection;
|
||||||
|
using Microsoft.AspNet.Hosting;
|
||||||
using Microsoft.AspNet.Identity;
|
using Microsoft.AspNet.Identity;
|
||||||
using Microsoft.AspNet.Identity.EntityFramework;
|
using Microsoft.AspNet.Identity.EntityFramework;
|
||||||
using Microsoft.Data.Entity;
|
using Microsoft.Data.Entity;
|
||||||
|
|
@ -100,5 +101,14 @@ namespace IdentitySamples
|
||||||
SampleData.InitializeIdentityDatabaseAsync(app.ApplicationServices).Wait();
|
SampleData.InitializeIdentityDatabaseAsync(app.ApplicationServices).Wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void Main(string[] args)
|
||||||
|
{
|
||||||
|
var application = new WebApplicationBuilder()
|
||||||
|
.UseConfiguration(WebApplicationConfiguration.GetDefault(args))
|
||||||
|
.UseStartup<Startup>()
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
application.Run();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"server": "Microsoft.AspNet.Server.Kestrel",
|
||||||
|
"server.urls": "http://localhost:41532/"
|
||||||
|
}
|
||||||
|
|
@ -1,42 +1,43 @@
|
||||||
{
|
{
|
||||||
"authors": [
|
"authors": [
|
||||||
"Microsoft"
|
"Microsoft"
|
||||||
],
|
],
|
||||||
"description": "Identity sample MVC application on K",
|
"description": "Identity sample MVC application on K",
|
||||||
"version": "1.0.0-*",
|
"version": "1.0.0-*",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Microsoft.AspNet.Mvc": "6.0.0-*",
|
"Microsoft.AspNet.Mvc": "6.0.0-*",
|
||||||
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
|
"Microsoft.AspNet.DataProtection.Extensions": "1.0.0-*",
|
||||||
"Microsoft.AspNet.DataProtection.Extensions": "1.0.0-*",
|
"Microsoft.AspNet.Diagnostics": "1.0.0-*",
|
||||||
"Microsoft.AspNet.Diagnostics": "1.0.0-*",
|
"Microsoft.AspNet.Identity": "3.0.0-*",
|
||||||
"Microsoft.AspNet.Identity": "3.0.0-*",
|
"Microsoft.AspNet.Identity.EntityFramework": "3.0.0-*",
|
||||||
"Microsoft.AspNet.Identity.EntityFramework": "3.0.0-*",
|
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-*",
|
||||||
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-*",
|
"Microsoft.AspNet.Authentication.Facebook": "1.0.0-*",
|
||||||
"Microsoft.AspNet.Authentication.Facebook": "1.0.0-*",
|
"Microsoft.AspNet.Authentication.Google": "1.0.0-*",
|
||||||
"Microsoft.AspNet.Authentication.Google": "1.0.0-*",
|
"Microsoft.AspNet.Authentication.Twitter": "1.0.0-*",
|
||||||
"Microsoft.AspNet.Authentication.Twitter": "1.0.0-*",
|
"Microsoft.AspNet.Authorization": "1.0.0-*",
|
||||||
"Microsoft.AspNet.Authorization": "1.0.0-*",
|
"Microsoft.AspNet.StaticFiles": "1.0.0-*",
|
||||||
"Microsoft.AspNet.StaticFiles": "1.0.0-*",
|
"Microsoft.AspNet.Server.Kestrel": "1.0.0-*",
|
||||||
"EntityFramework.Commands": "7.0.0-*",
|
"EntityFramework.Commands": "7.0.0-*",
|
||||||
"EntityFramework.MicrosoftSqlServer": "7.0.0-*",
|
"EntityFramework.MicrosoftSqlServer": "7.0.0-*",
|
||||||
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-*",
|
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-*",
|
||||||
"Microsoft.Extensions.Configuration.Json": "1.0.0-*",
|
"Microsoft.Extensions.Configuration.Json": "1.0.0-*",
|
||||||
"Microsoft.Extensions.OptionsModel": "1.0.0-*",
|
"Microsoft.Extensions.OptionsModel": "1.0.0-*",
|
||||||
"Microsoft.Extensions.Logging.Console": "1.0.0-*"
|
"Microsoft.Extensions.Logging.Console": "1.0.0-*"
|
||||||
|
},
|
||||||
|
"compilationOptions": {
|
||||||
|
"emitEntryPoint": true
|
||||||
|
},
|
||||||
|
"commands": {
|
||||||
|
"web": "IdentitySample.Mvc"
|
||||||
|
},
|
||||||
|
"webroot": ".",
|
||||||
|
"frameworks": {
|
||||||
|
"dnx451": {
|
||||||
|
"dependencies": {
|
||||||
|
"Microsoft.Extensions.Logging.NLog": "1.0.0-*"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"commands": {
|
"dnxcore50": {
|
||||||
"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:41532",
|
|
||||||
"run": "run server.urls=http://localhost:41532",
|
|
||||||
"ef": "EntityFramework.Commands"
|
|
||||||
},
|
|
||||||
"webroot": ".",
|
|
||||||
"frameworks": {
|
|
||||||
"dnx451": {
|
|
||||||
"dependencies": {
|
|
||||||
"Microsoft.Extensions.Logging.NLog": "1.0.0-*"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"dnxcore50": {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ using System.Threading.Tasks;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using Microsoft.AspNet.Builder;
|
using Microsoft.AspNet.Builder;
|
||||||
|
using Microsoft.AspNet.Hosting;
|
||||||
using Microsoft.AspNet.Http;
|
using Microsoft.AspNet.Http;
|
||||||
using Microsoft.AspNet.Http.Authentication;
|
using Microsoft.AspNet.Http.Authentication;
|
||||||
using Microsoft.AspNet.Http.Features.Authentication;
|
using Microsoft.AspNet.Http.Features.Authentication;
|
||||||
|
|
@ -29,7 +30,9 @@ namespace Microsoft.AspNet.Identity.InMemory
|
||||||
[Fact]
|
[Fact]
|
||||||
public void UseIdentityThrowsWithoutAddIdentity()
|
public void UseIdentityThrowsWithoutAddIdentity()
|
||||||
{
|
{
|
||||||
Assert.Throws<InvalidOperationException>(() => TestServer.Create(app => app.UseIdentity()));
|
var builder = new WebApplicationBuilder()
|
||||||
|
.Configure(app => app.UseIdentity());
|
||||||
|
Assert.Throws<InvalidOperationException>(() => new TestServer(builder));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -179,87 +182,89 @@ namespace Microsoft.AspNet.Identity.InMemory
|
||||||
|
|
||||||
private static TestServer CreateServer(Action<IServiceCollection> configureServices = null, Func<HttpContext, Task> testpath = null, Uri baseAddress = null)
|
private static TestServer CreateServer(Action<IServiceCollection> configureServices = null, Func<HttpContext, Task> testpath = null, Uri baseAddress = null)
|
||||||
{
|
{
|
||||||
var server = TestServer.Create(app =>
|
var builder = new WebApplicationBuilder()
|
||||||
{
|
.Configure(app =>
|
||||||
app.UseIdentity();
|
|
||||||
app.Use(async (context, next) =>
|
|
||||||
{
|
{
|
||||||
var req = context.Request;
|
app.UseIdentity();
|
||||||
var res = context.Response;
|
app.Use(async (context, next) =>
|
||||||
var userManager = context.RequestServices.GetRequiredService<UserManager<TestUser>>();
|
|
||||||
var signInManager = context.RequestServices.GetRequiredService<SignInManager<TestUser>>();
|
|
||||||
PathString remainder;
|
|
||||||
if (req.Path == new PathString("/normal"))
|
|
||||||
{
|
{
|
||||||
res.StatusCode = 200;
|
var req = context.Request;
|
||||||
}
|
var res = context.Response;
|
||||||
else if (req.Path == new PathString("/createMe"))
|
var userManager = context.RequestServices.GetRequiredService<UserManager<TestUser>>();
|
||||||
|
var signInManager = context.RequestServices.GetRequiredService<SignInManager<TestUser>>();
|
||||||
|
PathString remainder;
|
||||||
|
if (req.Path == new PathString("/normal"))
|
||||||
|
{
|
||||||
|
res.StatusCode = 200;
|
||||||
|
}
|
||||||
|
else if (req.Path == new PathString("/createMe"))
|
||||||
|
{
|
||||||
|
var result = await userManager.CreateAsync(new TestUser("hao"), TestPassword);
|
||||||
|
res.StatusCode = result.Succeeded ? 200 : 500;
|
||||||
|
}
|
||||||
|
else if (req.Path == new PathString("/createSimple"))
|
||||||
|
{
|
||||||
|
var result = await userManager.CreateAsync(new TestUser("simple"), "aaaaaa");
|
||||||
|
res.StatusCode = result.Succeeded ? 200 : 500;
|
||||||
|
}
|
||||||
|
else if (req.Path == new PathString("/protected"))
|
||||||
|
{
|
||||||
|
res.StatusCode = 401;
|
||||||
|
}
|
||||||
|
else if (req.Path.StartsWithSegments(new PathString("/pwdLogin"), out remainder))
|
||||||
|
{
|
||||||
|
var isPersistent = bool.Parse(remainder.Value.Substring(1));
|
||||||
|
var result = await signInManager.PasswordSignInAsync("hao", TestPassword, isPersistent, false);
|
||||||
|
res.StatusCode = result.Succeeded ? 200 : 500;
|
||||||
|
}
|
||||||
|
else if (req.Path == new PathString("/twofactorRememeber"))
|
||||||
|
{
|
||||||
|
var user = await userManager.FindByNameAsync("hao");
|
||||||
|
await signInManager.RememberTwoFactorClientAsync(user);
|
||||||
|
res.StatusCode = 200;
|
||||||
|
}
|
||||||
|
else if (req.Path == new PathString("/isTwoFactorRememebered"))
|
||||||
|
{
|
||||||
|
var user = await userManager.FindByNameAsync("hao");
|
||||||
|
var result = await signInManager.IsTwoFactorClientRememberedAsync(user);
|
||||||
|
res.StatusCode = result ? 200 : 500;
|
||||||
|
}
|
||||||
|
else if (req.Path == new PathString("/twofactorSignIn"))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else if (req.Path == new PathString("/me"))
|
||||||
|
{
|
||||||
|
var auth = new AuthenticateContext("Application");
|
||||||
|
auth.Authenticated(context.User, new AuthenticationProperties().Items, new AuthenticationDescription().Items);
|
||||||
|
Describe(res, auth);
|
||||||
|
}
|
||||||
|
else if (req.Path.StartsWithSegments(new PathString("/me"), out remainder))
|
||||||
|
{
|
||||||
|
var auth = new AuthenticateContext(remainder.Value.Substring(1));
|
||||||
|
await context.Authentication.AuthenticateAsync(auth);
|
||||||
|
Describe(res, auth);
|
||||||
|
}
|
||||||
|
else if (req.Path == new PathString("/testpath") && testpath != null)
|
||||||
|
{
|
||||||
|
await testpath(context);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await next();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.ConfigureServices(services =>
|
||||||
|
{
|
||||||
|
services.AddIdentity<TestUser, TestRole>();
|
||||||
|
services.AddSingleton<IUserStore<TestUser>, InMemoryUserStore<TestUser>>();
|
||||||
|
services.AddSingleton<IRoleStore<TestRole>, InMemoryRoleStore<TestRole>>();
|
||||||
|
if (configureServices != null)
|
||||||
{
|
{
|
||||||
var result = await userManager.CreateAsync(new TestUser("hao"), TestPassword);
|
configureServices(services);
|
||||||
res.StatusCode = result.Succeeded ? 200 : 500;
|
|
||||||
}
|
|
||||||
else if (req.Path == new PathString("/createSimple"))
|
|
||||||
{
|
|
||||||
var result = await userManager.CreateAsync(new TestUser("simple"), "aaaaaa");
|
|
||||||
res.StatusCode = result.Succeeded ? 200 : 500;
|
|
||||||
}
|
|
||||||
else if (req.Path == new PathString("/protected"))
|
|
||||||
{
|
|
||||||
res.StatusCode = 401;
|
|
||||||
}
|
|
||||||
else if (req.Path.StartsWithSegments(new PathString("/pwdLogin"), out remainder))
|
|
||||||
{
|
|
||||||
var isPersistent = bool.Parse(remainder.Value.Substring(1));
|
|
||||||
var result = await signInManager.PasswordSignInAsync("hao", TestPassword, isPersistent, false);
|
|
||||||
res.StatusCode = result.Succeeded ? 200 : 500;
|
|
||||||
}
|
|
||||||
else if (req.Path == new PathString("/twofactorRememeber"))
|
|
||||||
{
|
|
||||||
var user = await userManager.FindByNameAsync("hao");
|
|
||||||
await signInManager.RememberTwoFactorClientAsync(user);
|
|
||||||
res.StatusCode = 200;
|
|
||||||
}
|
|
||||||
else if (req.Path == new PathString("/isTwoFactorRememebered"))
|
|
||||||
{
|
|
||||||
var user = await userManager.FindByNameAsync("hao");
|
|
||||||
var result = await signInManager.IsTwoFactorClientRememberedAsync(user);
|
|
||||||
res.StatusCode = result ? 200 : 500;
|
|
||||||
}
|
|
||||||
else if (req.Path == new PathString("/twofactorSignIn"))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
else if (req.Path == new PathString("/me"))
|
|
||||||
{
|
|
||||||
var auth = new AuthenticateContext("Application");
|
|
||||||
auth.Authenticated(context.User, new AuthenticationProperties().Items, new AuthenticationDescription().Items);
|
|
||||||
Describe(res, auth);
|
|
||||||
}
|
|
||||||
else if (req.Path.StartsWithSegments(new PathString("/me"), out remainder))
|
|
||||||
{
|
|
||||||
var auth = new AuthenticateContext(remainder.Value.Substring(1));
|
|
||||||
await context.Authentication.AuthenticateAsync(auth);
|
|
||||||
Describe(res, auth);
|
|
||||||
}
|
|
||||||
else if (req.Path == new PathString("/testpath") && testpath != null)
|
|
||||||
{
|
|
||||||
await testpath(context);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
await next();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
var server = new TestServer(builder);
|
||||||
services =>
|
|
||||||
{
|
|
||||||
services.AddIdentity<TestUser, TestRole>();
|
|
||||||
services.AddSingleton<IUserStore<TestUser>, InMemoryUserStore<TestUser>>();
|
|
||||||
services.AddSingleton<IRoleStore<TestRole>, InMemoryRoleStore<TestRole>>();
|
|
||||||
if (configureServices != null)
|
|
||||||
{
|
|
||||||
configureServices(services);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
server.BaseAddress = baseAddress;
|
server.BaseAddress = baseAddress;
|
||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue