Google OAuth in ASP.NET 5 MVC 6

I am new to ASP.NET vNext and I cannot find how to configure Google OAuth.

I have an uncomment line in Startup.cs:

 app.UseGoogleAuthentication();

But where should I configure it? I tried to reproduce the pattern:

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

But

services.Configure<GoogleOAuth2AuthenticationOptions>

Not recognized even if the dependency is present in project.json:

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

What am I missing?

+4
source share
2 answers

There is a sample at https://github.com/aspnet/Security/blob/dev/samples/SocialSample/Startup.cs .

I have not tried it, but it looks like you are setting it up 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);
        }
    };

});
+2
source

If you use a configuration repository, for example,

Configuration["Authentication:MicrosoftAccount:ClientId"]; 

, ( " Google OAuth" ), , SecretManager, ASP.NET ( facebook, ). , , . Google , , :

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

, .

0

Source: https://habr.com/ru/post/1614471/


All Articles