ASP.NET 5 MVC 6中的Google OAuth

我是ASP.NET vNext的新手,我找不到如何配置Google OAuth.

我在Startup.cs中取消注释该行:

 app.UseGoogleAuthentication();

但我应该在哪里配置呢?我试图复制模式:

services.Configure<MicrosoftAccountAuthenticationOptions>(options =>
{
    options.ClientId = Configuration["Authentication:MicrosoftAccount:ClientId"];
    options.ClientSecret = Configuration["Authentication:MicrosoftAccount:ClientSecret"];
});

services.Configure<GoogleOAuth2AuthenticationOptions>

即使project.json中存在依赖项,也无法识别:

"Microsoft.AspNet.Authentication.Google": "1.0.0-beta5",

我错过了什么?

最佳答案 有一个样本在
https://github.com/aspnet/Security/blob/dev/samples/SocialSample/Startup.cs.

我没有尝试过,但看起来你使用app.UseGoogleAuthentication()进行配置:

app.UseGoogleAuthentication(options =>
{
    options.ClientId = "560027070069-37ldt4kfuohhu3m495hk2j4pjp92d382.apps.googleusercontent.com";
    options.ClientSecret = "n2Q-GEw9RQjzcRbU3qhfTj8f";
    options.Events = new OAuthEvents()
    {
        OnRemoteError = ctx =>

        {
            ctx.Response.Redirect("/error?ErrorMessage=" + UrlEncoder.Default.Encode(ctx.Error.Message));
            ctx.HandleResponse();
            return Task.FromResult(0);
        }
    };

});
点赞