2015-11-04 94 views
4

我是ASP.NET vNext的新手,我没有找到如何配置Google OAuth。在ASP.NET 5中的Google OAuth MVC 6

我已经取消注释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", 

我缺少什么?

回答

2

样品在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); 
     } 
    }; 

}); 
0

如果您使用的配置存储这样

Configuration["Authentication:MicrosoftAccount:ClientId"]; 

然后您还缺少了什么(如果这就是'configure Google OAuth'的含义),那么您需要按照the ASP.NET docs(他们使用Facebook,但您可以在其中放置任何您想要的键)中的值存储在SecretManager中, 。这是一个命令行工具,它可以避免您将密钥存储在代码中。在谷歌的情况下,你可能想将其更改为:

Configuration["Authentication:Google:ClientID"]; 
Configuration["Authentication:Google:ClientSecret"]; 

但它可以是任何你想要的。

相关问题