我有问题。我在本地主机上使用Startup.cs中的以下代码
ConfigureServices
方法。没有
oauthOptions.Events.OnRedirectToIdentityProvider
我无法重定向。但是我的问题是用户无法进行身份验证。有人可以帮我吗?
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultForbidScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultSignOutScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddOpenIdConnect(oauthOptions =>
{
oauthOptions.ClientId = "b6514a30-c3dc-0136-0d4f-0685c268206c137310";
oauthOptions.ClientSecret = "secret here";
oauthOptions.Authority = "https://test.onelogin.com/oidc";
oauthOptions.ResponseType = OpenIdConnectResponseType.Code;
oauthOptions.GetClaimsFromUserInfoEndpoint = true;
oauthOptions.Events.OnRedirectToIdentityProvider = (context) =>
{
context.ProtocolMessage.RedirectUri = "https://ed40a182.ngrok.io/home/index";
return Task.FromResult(0);
};
oauthOptions.TokenValidationParameters = new TokenValidationParameters
{
NameClaimType = OpenIdConnectConstants.Claims.Name,
RoleClaimType = OpenIdConnectConstants.Claims.Role,
ValidateIssuer = true
};
oauthOptions.SaveTokens = true;
})
.AddCookie()
;