c# - 应该使用什么来代替 UseGoogleAuthentication 方法 (IAppBuilder)?

标签 c# asp.net asp.net-mvc security oauth

MSDN 文档 states那:

GoogleAuthenticationExtensions.UseGoogleAuthentication Method (IAppBuilder)

Note: This API is now obsolete.

还有什么选择?应该使用什么代替此方法?

最佳答案

您可以像这样使用 Google OAuth2 中间件:

private void ConfigureAuth(IAppBuilder app)
{
    var cookieOptions = new CookieAuthenticationOptions
    {
        LoginPath = new PathString("/Account/Login")
    };

    app.UseCookieAuthentication(cookieOptions);

    app.SetDefaultSignInAsAuthenticationType(cookieOptions.AuthenticationType);

    app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions
    {
        ClientId = ConfigurationManager.AppSettings["ClientId"],
        ClientSecret = ConfigurationManager.AppSettings["ClientSecret"]
    });
}

您可以在以下位置创建客户端 ID 和密码:https://console.developers.google.com/

关于c# - 应该使用什么来代替 UseGoogleAuthentication 方法 (IAppBuilder)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29717600/

相关文章:

c# - 在 PC 中使用网络摄像头作为环境光传感器

c# - 无法从共享点列表加载计算字段

C# 并行 foreach - System.AggregateException : One or more errors occurred. ---> System.IndexOutOfRangeException

asp.net - 从 WebForms 调用 ASP.NET MVC3 区域

jquery - ASP.NET MVC 和 Jquery DatePicker

c# - 如何在 ASP.NET MVC 中应用长轮询技术?

c# - 使用 Json.net - C# 对象的部分自定义序列化

asp.net - 在asp.net中获取radgrid telerik隐藏列的值

c# - 如何获取动态填充控件的值

c# - JQuery 为 MVC Post 设置隐藏输入