2017-07-19 1 views
1

InvalidOperationException: Aucun gestionnaire d'authentification est configuré pour gérer le système: FacebookAsp.net de base, Connexion externe, aucun gestionnaire d'authentification est configuré pour gérer le système: Facebook

[HttpGet] 
    [AllowAnonymous] 
    public IActionResult ExternalLogin(string provider, string returnUrl = "CampAccount") 
    { 
     // Request a redirect to the external login provider. 
     var redirectUrl = Url.Action(nameof(ExternalLoginCallback), "Account", new { ReturnUrl = returnUrl }); 
     var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl); 
     return Challenge(properties, provider);//Error occurs here 
    } 

Si quelqu'un passe par le même problème, je serai vraiment reconnaissant pour votre idea'a ou des suggestions sur ce que je me trompe do.J'utilise (IdentityServer4).

Startup.cs

public class Startup 
{ 
    public Startup(IHostingEnvironment env) 
    { 
     var builder = new ConfigurationBuilder() 
      .SetBasePath(env.ContentRootPath) 
      .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) 
      .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true); 

     if (env.IsDevelopment()) 
     { 
      // For more details on using the user secret store see https://go.microsoft.com/fwlink/?LinkID=532709 
      builder.AddUserSecrets<Startup>(); 
     } 

     builder.AddEnvironmentVariables(); 
     Configuration = builder.Build(); 
    } 

    public IConfigurationRoot Configuration { get; } 

    // This method gets called by the runtime. Use this method to add services to the container. 
    public void ConfigureServices(IServiceCollection services) 
    { 
     // Add framework services. 
     services.AddDbContext<ApplicationDbContext>(options => 
      options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); 
     services.AddDbContext<CampionzDBContext>(options => 
      options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); 
     // if using IdentityServer4 

     services.AddIdentity<ApplicationUser, IdentityRole>() 
      .AddEntityFrameworkStores<ApplicationDbContext>() 
      .AddDefaultTokenProviders(); 

     services.AddMvc(); 

     // Adds a default in-memory implementation of IDistributedCache. 
     services.AddDistributedMemoryCache(); 
     services.AddSession(); 
     // 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.UseDeveloperExceptionPage(); 
      app.UseDatabaseErrorPage(); 
      app.UseBrowserLink(); 
     } 
     else 
     { 
      app.UseExceptionHandler("/Home/Error"); 
     } 
     app.UseCookieAuthentication(new CookieAuthenticationOptions 
     { 
      AutomaticAuthenticate = true, 
      AutomaticChallenge = true, 
      ExpireTimeSpan = TimeSpan.FromMinutes(60) 
     }); 

     app.UseStaticFiles(); 

     app.UseIdentity(); 

     // Add external authentication middleware below. To configure them please see https://go.microsoft.com/fwlink/?LinkID=532715 

     app.UseMvc(routes => 
     { 
      routes.MapRoute(
       name: "default", 
       template: "{controller=Home}/{action=Index}/{id?}"); 
     }); 


     //External login Secrets 
     app.UseFacebookAuthentication(new FacebookOptions 
     { 
      AppId = "###",// Configuration["Authentication:Facebook:ClientID"], 
      AppSecret = "###",//Configuration["Authentication:Facebook:ClientSecret"], 
     }); 

     app.UseGoogleAuthentication(new GoogleOptions 
     { 
      ClientId = "###",// Configuration["Authentication:Facebook:ClientID"], 
      ClientSecret = "###",//Configuration["Authentication:Facebook:ClientSecret"], 
     }); 
    } 
} 

Répondre

1

essayez de placer intergiciels d'authentification externes entre UseIdentity et UseMvc

app.UseIdentity(); 

Après cela mis intergiciels externes

app.UseFacebookAuthentication(new FacebookOptions 
    { 
     AppId = "###",// Configuration["Authentication:Facebook:ClientID"], 
     AppSecret = "###",//Configuration["Authentication:Facebook:ClientSecret"], 
    }); 

    app.UseGoogleAuthentication(new GoogleOptions 
    { 
     ClientId = "###",// Configuration["Authentication:Facebook:ClientID"], 
     ClientSecret = "###",//Configuration["Authentication:Facebook:ClientSecret"], 
    }); 

et dernier bloc doit être

app.UseMvc(routes => 
    { 
     routes.MapRoute(
      name: "default", 
      template: "{controller=Home}/{action=Index}/{id?}"); 
    }); 
0

Oui modèle ne importe alot.so Suivre le bon modèle qui est mentionné ci-dessus au poste et au-dessous ici.

  1. app.UseIdentity();
  2. app.UseFacebookAuthentication(new FacebookOptions...);// Others Authenticater also will come here like Google,LinkedIn etc also will come here
  3. app.UseMvc(routes =>{...});