Reputation: 501
I'm new to ASP.NET vNext and I don't find how to configure Google OAuth.
I have uncomment the line in Startup.cs:
app.UseGoogleAuthentication();
But where am I supposed to configure it? I tried to replicate the pattern:
services.Configure<MicrosoftAccountAuthenticationOptions>(options =>
{
options.ClientId = Configuration["Authentication:MicrosoftAccount:ClientId"];
options.ClientSecret = Configuration["Authentication:MicrosoftAccount:ClientSecret"];
});
But
services.Configure<GoogleOAuth2AuthenticationOptions>
Isn't recognized even if the dependency is present in project.json:
"Microsoft.AspNet.Authentication.Google": "1.0.0-beta5",
What am I missing?
Upvotes: 4
Views: 2251
Reputation: 5769
If you're using the configuration store like this
Configuration["Authentication:MicrosoftAccount:ClientId"];
then what you're also missing (if that's what you mean by 'configure Google OAuth') is the part where you store the values in the SecretManager as described in the ASP.NET docs (they use facebook but you can just put whatever keys you want in there). It's a command line tool and it avoids you storing the keys in the code like that. In Google's case you'd probably want to change it to:
Configuration["Authentication:Google:ClientID"];
Configuration["Authentication:Google:ClientSecret"];
but it can be whatever you want.
Upvotes: 0
Reputation: 1912
There is a sample at https://github.com/aspnet/Security/blob/dev/samples/SocialSample/Startup.cs.
I haven't tried it, but it looks like you configure it using 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);
}
};
});
Upvotes: 2