添加包
Microsoft.AspNetCore.Identity
Microsoft.AspNetCore.Identity.EntityFrameworkCore
Microsoft.AspNetCore.Authentication.Google
然后在启动中:
public void ConfigureServices(IServiceCollection services)
{
services.AddIdentity<IdentityUser, IdentityRole>();
services.AddAuthentication(
v => {
v.DefaultAuthenticateScheme = GoogleDefaults.AuthenticationScheme;
v.DefaultChallengeScheme = GoogleDefaults.AuthenticationScheme;
}).AddGoogle(googleOptions =>
{
googleOptions.ClientId = "CLIENT ID";
googleOptions.ClientSecret = "CLIENT SECRET";
});
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseAuthentication()
.UseMvc();
}
这里有一个最小的工作示例:
https ://github.com/mjrmua/Asp.net-Core-2.0-google-authentication-example