Google 身份验证和 jwt 承载

时间:2021-02-24 10:51:59

标签: asp.net-core web asp.net-web-api .net-core asp.net-web-api2

我有一个带有 jwt 不记名身份验证的 .Net Core Api。我希望最终用户能够正常连接(使用电子邮件和密码)或使用谷歌帐户。 截至目前,当用户登录(使用电子邮件和密码)时,他会收到一个令牌。

我的startup.cs

services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes("AFhu9aVrbdUN3G4Vv87jWA7gCSuJG8c8D7cp7XrUMayEtcryWpGJzDQMnV7")),
                    ValidateIssuer = false,
                    ValidateAudience = false
                };
                
            });

我已经尝试过:https://docs.microsoft.com/en-us/aspnet/core/security/authentication/social/google-logins?view=aspnetcore-5.0

我添加了这个:

services.AddAuthentication()
        .AddGoogle(options =>
        {
            IConfigurationSection googleAuthNSection =
                Configuration.GetSection("Authentication:Google");

            options.ClientId = googleAuthNSection["ClientId"];
            options.ClientSecret = googleAuthNSection["ClientSecret"];
        });

我不知道如何从这里继续

0 个答案:

没有答案