admin管理员组文章数量:1418103
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";
});
本文标签: aspnet coreNET OAuth2 Signon Google serverside amp Azure SignonStack Overflow
版权声明:本文标题:asp.net core - .NET OAuth2 Sign-on Google server-side & Azure Sign-on - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745267094a2650668.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论