我正在構建使用asp.net 5 rc2 api。我試圖執行openiddict-core,發現本地帳戶爲here,我也希望允許用戶使用外部登錄名,例如google。沒有身份驗證處理程序配置爲驗證該方案:Microsoft.AspNet.Identity.External
我已經設置了這一切,但是當我嘗試實施谷歌認證,並且我稱這種代碼
var info = await _signInManager.GetExternalLoginInfoAsync();
我得到的稱號錯誤消息。
在客戶端上,我使用了Satellizer找到的here,它負責打開Google提示窗口並將回調發送到我的AuthController Google方法,這是您在其他mvc6示例中看到的正常ChallengeResult代碼。
我已經寫代碼來獲取用戶手工細節和工作,但我想我會用已建signInManager代替,而不是再現輪...
我可能沒有正確設置好了,因爲所有的例子似乎都使用cookies,我猜測這是因爲它們是mvc6 web應用程序,而不是api。我不想使用cookies,但這可能是我的問題。
現在有些代碼。
startup.cs
public void ConfigureServices(IServiceCollection services)
{
// Add MVC services to the services container.
services.AddMvc();
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(_configuration["Data:DefaultConnection:ConnectionString"]));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders()
.AddOpenIddict(); // Add the OpenIddict services after registering the Identity services.
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
// use jwt bearer authentication
app.UseJwtBearerAuthentication(options =>
{
options.AutomaticAuthenticate = true;
options.AutomaticChallenge = true;
options.RequireHttpsMetadata = false;
options.Audience = "http://localhost:5000/";
options.Authority = "http://localhost:5000/";
});
// Add all the external providers you need before registering OpenIddict:
app.UseGoogleAuthentication(options =>
{
options.AutomaticAuthenticate = true;
//options.AutomaticChallenge = true;
options.ClientId = "XXX";
options.ClientSecret = "XXX";
});
//app.UseFacebookAuthentication();
app.UseOpenIddict();
// Enable all static file middleware
app.UseStaticFiles();
// Enable Mvc for view controller, and
// default all routes to the Home controller
app.UseMvc(options =>
{
options.MapRoute(
name: "default",
template: "{*url}",
defaults: new { controller = "Home", action = "Index" });
});
}
AuthController.cs
ExternalLoginModel.cs
public class ExternalLoginModel
{
public string Code { get; set; }
public string ClientId { get; set; }
public string RedirectUri { get; set; }
}
可能重複[沒有認證處理程序配置爲處理該方案:自動](https://stackoverflow.com/questions/33825058/no-authentication-handler-is-configured-to-handle-the-scheme-自動) –