2015-11-04 99 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"]; 

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

相關問題