Gav*_*ide 3 asp.net-mvc mongodb asp.net-identity asp.net-core-mvc asp.net-identity-3
我正在运行ASP.NET MVC 6的RC1,并希望使用MongoDB身份提供程序.
我已经实现了Grant Megrabyan 的提供程序,它正在很好地注册新用户并允许他们登录但我得到错误:
InvalidOperationException:没有配置身份验证处理程序来处理该方案:Microsoft.AspNet.Identity.External Microsoft.AspNet.Http.Authentication.Internal.DefaultAuthenticationManager.d__13.MoveNext()
我之前使用EntityFramework进行了外部登录,所以我假设我的第三方auth配置可能是正确的.
当用户点击登录Facebook时,他们将被重定向到以下操作:
// POST: /Account/ExternalLogin
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public IActionResult ExternalLogin(string provider, string returnUrl = null)
{
// Request a redirect to the external login provider.
var redirectUrl = Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl });
var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);
return new ChallengeResult(provider, properties);
}
Run Code Online (Sandbox Code Playgroud)
此时没有异常抛出,但是当Facebook从ChallengeResponse返回时,它会发送一个GET到:http:// localhost:51265/signin-facebook?code = [facebook user token].
此时ASP.NET抛出异常:
Facebook制作的回调网址似乎没有意义.当然应该返回我的ExternalLoginCallback操作?
这是关于我的想法?!
如果有人能看到我出错的地方那么我就是一个非常快乐的人.
我的startup.cs:
public class Startup
{
public Startup(IHostingEnvironment env)
{
// Set up configuration sources.
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
if (env.IsDevelopment())
{
// For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
builder.AddUserSecrets();
}
builder.AddEnvironmentVariables();
Configuration = builder.Build();
}
public IConfigurationRoot Configuration { get; set; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<ApplicationDbContext>();
// Add framework services.
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddMongoStores<ApplicationDbContext, ApplicationUser, IdentityRole>()
.AddDefaultTokenProviders();
services.AddMvc();
// Add application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment())
{
app.UseBrowserLink();
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear());
app.UseStaticFiles();
app.UseFacebookAuthentication(options =>
{
options.AppId = "removed";
options.AppSecret = "removed";
});
app.UseIdentity();
app.UseMvcWithDefaultRoute();
}
// Entry point for the application.
public static void Main(string[] args) => WebApplication.Run<Startup>(args);
}
Run Code Online (Sandbox Code Playgroud)
打电话UseFacebookAuthentication之后UseIdentity,但之前UseMvc;
app.UseIdentity();
app.UseFacebookAuthentication(options =>
{
options.AppId = "removed";
options.AppSecret = "removed";
});
app.UseMvcWithDefaultRoute();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1474 次 |
| 最近记录: |