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 badge1 Answer
Reset to default 0HttpContext 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条)