应该使用什么来代替UseGoogleAuthentication Method(IAppBuilder)?

时间:2015-04-18 12:52:07

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

MSDN文档states

  

GoogleAuthenticationExtensions.UseGoogleAuthentication Method   (IAppBuilder)

     

注意:此API现在已过时

替代方案是什么?应该用什么代替这种方法?

1 个答案:

答案 0 :(得分:4)

您可以像这样使用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"]
    });
}

您可以在https://console.developers.google.com/

创建客户端ID和密码