Jan*_*ivZ 9 c# .net-core asp.net-core asp.net-core-webapi ef-core-2.0
TL; DR - 如何将身份验证添加到未使用auth启动的现有默认核心2 web api项目.
详细信息 - 我已经有一个现有的.net core 2 web api项目,没有配置身份验证,我正在使用实体框架核心.
它打开像 -
PIC 1 - 未选择身份验证
我想将Google身份验证添加到我现有的项目中,就像打开它一样
PIC 2 - 选择了单个用户帐户
但我找不到任何有关添加这些功能+脚手架和迁移的资源 - 我所能找到的是从核心v1升级到2的链接.
有任何想法吗?
谢谢!
Mur*_*ray 16
添加包
Microsoft.AspNetCore.Identity
Microsoft.AspNetCore.Identity.EntityFrameworkCore
Microsoft.AspNetCore.Authentication.Google
Run Code Online (Sandbox Code Playgroud)
然后在初创公司:
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();
}
Run Code Online (Sandbox Code Playgroud)
这里是一个最小的工作示例:https: //github.com/mjrmua/Asp.net-Core-2.0-google-authentication-example
归档时间: |
|
查看次数: |
4208 次 |
最近记录: |