在 dotnet core 2.0 有一个新的 Security 项目可以给我们使用。
里面东西很多哦!而且扩展起来也非常方便~
在配置文件里添加以下节点
如果只想本地使用,可以试试 `secrets.json` (Right click -> Manage User Secrets)
{ "Authentication": { "Google": { "ClientId": "<your-client-id>", "ClientSecret": "<your-client-secret>" } } }
|
安装 nuget 包 Microsoft.AspNet.Authentication.Google
代码也非常简单
public void ConfigureServices(IServiceCollection services) { services.AddAuthentication() .AddGoogle(googleOptions => { googleOptions.ClientId = Configuration.GetSection("Authentication")["Google:ClientId"]; googleOptions.ClientSecret = Configuration.GetSection("Authentication")["Google:ClientSecret"]; }); }
|
其他
- ClientId 什么的是自己申请的,到对应的服务商那边申请就可以了。
- 国内的 qq 新浪 什么的,不想自己写,可以去 github 搜索,已经有人提供了,可以直接使用的。