asp.net core - .NET OAuth2 Sign-on Google server-side & Azure Sign-on - Stack Overflow

I am having trouble finding the problem with my authentication services. I want to be able to log in wi

I am having trouble finding the problem with my authentication services. I want to be able to log in with google OAuth 2.0 as well as Azure. For now only azure works. My code goes as followed:

builder.Services
.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAd"));

builder.Services
.AddAuthentication()
.AddGoogle(options =
{
    IConfigurationSection googleAuthNSection = 
    builder.Configuration.GetSection("Authentication:Google");
    options.ClientId = googleAuthNSection["ClientId"];
    options.ClientSecret = googleAuthNSection["ClientSecret"];
});

With this sign in button:

<MudButton Href="/signin-google" Variant="Variant.Filled" Color="Color.Primary">Log in with Google</MudButton>

The problem is that the google sign-on always results in this and I can't find the problem:

Error google login redirect

I have tried editing the redirect uris in google cloud, but that also didn't work. Redirect URIS

I think it is a cookie issue, but I don't know how to fix it so both login options would work.

I am having trouble finding the problem with my authentication services. I want to be able to log in with google OAuth 2.0 as well as Azure. For now only azure works. My code goes as followed:

builder.Services
.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAd"));

builder.Services
.AddAuthentication()
.AddGoogle(options =
{
    IConfigurationSection googleAuthNSection = 
    builder.Configuration.GetSection("Authentication:Google");
    options.ClientId = googleAuthNSection["ClientId"];
    options.ClientSecret = googleAuthNSection["ClientSecret"];
});

With this sign in button:

<MudButton Href="/signin-google" Variant="Variant.Filled" Color="Color.Primary">Log in with Google</MudButton>

The problem is that the google sign-on always results in this and I can't find the problem:

Error google login redirect

I have tried editing the redirect uris in google cloud, but that also didn't work. Redirect URIS

I think it is a cookie issue, but I don't know how to fix it so both login options would work.

Share Improve this question edited Feb 3 at 7:59 Qiang Fu 9,4171 gold badge6 silver badges16 bronze badges asked Jan 31 at 10:43 Thomas VerbruggenThomas Verbruggen 111 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

HttpContext can only have one user.So you could login either Azure or Google, but not at same time. Since they both implicitly use default cookie which named .AspNetCore.Cookies, you need to set different cookie for one of them.

builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApp(builder.Configuration.GetSection("AzureAd"));

builder.Services.AddAuthentication()
.AddCookie("GoogleAuthCookieScheme", options =>
{
    options.Cookie.Name = "MyGoogleAuth";
})
.AddGoogle(options =>
{
    IConfigurationSection googleAuthNSection = builder.Configuration.GetSection("Authentication:Google");
    options.ClientId = googleAuthNSection["ClientId"];
    options.ClientSecret = googleAuthNSection["ClientSecret"];
    options.SignInScheme = "GoogleAuthCookieScheme";
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745267095a4619523.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信