Google JWT Authentication with AspNet Core 2.0

后端 未结 2 1029
日久生厌
日久生厌 2020-12-03 04:21

I am trying to integrate google authentication in my ASP.NET Core 2.0 web api and I cannot figure out how to get it to work.

I have this code in my Startup.cs

2条回答
  •  有刺的猬
    2020-12-03 04:45

    I just published a NuGet package to handle validation of Google OpenID Connect tokens.

    The package relies on Microsoft's JWT validation and authentication handler from Microsoft.AspNetCore.Authentication.JwtBearer, with some added validation around hosted domains.

    It contains a single public extension method, UseGoogle, on JwtBearerOptions that lets you configure the handler to validate Google OpenID Connect tokens, without other dependencies:

    services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
        .AddJwtBearer(jwt => jwt.UseGoogle(
            clientId: "",
            hostedDomain: ""));
    

    If you want to take a look at the source, you can find it here.

提交回复
热议问题