ASP.Net Core Google Authentication

I am having google authentication issue in my .net application .net IP applications. My use case is simple, get bearer token from google put token in authorization header as "Bearer {token}" and call my web api.

But I cannot get it to work. After I get the token from google at the following url:

https://accounts.google.com/o/oauth2/v2/auth?scope=email%20openid&include_granted_scopes=true&state=some_test_state&redirect_uri=http%3A%2F%2Flocalhost%3A53512&response_type=token&client_id={someClientID}

I will call my api with the title:

Authorization: Bearer {TokenValue}

      

But every time I get 401 Unauthorized.

This is my launch class:

public static IConfigurationRoot Configuration { get; private set; }

// This method gets called by the runtime. Use this method to add services to the container
public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();

    // Pull in any SDK configuration from Configuration object
    services.AddDefaultAWSOptions(Configuration.GetAWSOptions());

    // Add S3 to the ASP.NET Core dependency injection framework.
    services.AddAWSService<Amazon.S3.IAmazonS3>();

    IocConfig.Configure(services);
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    loggerFactory.AddLambdaLogger(Configuration.GetLambdaLoggerOptions());

    var googleOptions = new GoogleOptions
    {
        AuthenticationScheme = "Google",
        ClientId = "clientid",
        ClientSecret = "cs",
        SignInScheme = "Google"
    };

    app.UseGoogleAuthentication(googleOptions);
    app.UseDeveloperExceptionPage();
    app.UseMvc();
}

      

+3


source to share





All Articles