基本上我的使用战网按钮登录在这里发送请求:
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddCookie(options =>
{
options.LoginPath = "/login";
options.LogoutPath = "/logout";
})
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ValidIssuer = Configuration["Jwt:Issuer"],
ValidAudience = Configuration["Jwt:Audience"],
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:Key"]))
};
})
.AddBattleNet(options =>
{
options.ClientId = Configuration["BattleNet:ClientId"];
options.ClientSecret = Configuration["BattleNet:ClientSecret"];
options.Region = BattleNetAuthenticationRegion.Europe;
})
[AllowAnonymous]
[HttpPost(nameof(ExternalLogin))]
public IActionResult ExternalLogin(string provider, string returnUrl = null)
{
var properties = new AuthenticationProperties
{
RedirectUri = Url.Action("ExternalLoginCallback"),
Items =
{
{ "scheme", provider},
{ "returnUrl", returnUrl }
}
};
return Challenge(properties, provider);
}
突然间我收到了这个错误
CORS 错误:
跨域请求被阻止:同源策略不允许在https://eu.battle.net/oauth/authorize?client_id= *&scope=d3.profile%20openid&response_type=code&redirect_uri=https%3A%2F%2Flocalhost读取远程资源%3A44333%2Fapi%2Fuser%2Fexternallogincallback&state=CfDJ8GNva7rF4-dPly4Z3xuUAIb6108sCNggQc6reYXjMJrGmdWZbri-N715ueCZ2Ksw9Q47k8SX1xG-c3zDck-mXT8h8mvEY5_41ox7C9OsU-PStXqUsD6npNcMBhCr16Qh1valIQ6REKTMjLiilO5wbnx1349I2SwQfJevGwKZqC4o4PElfF6kPaPmRa5Eslquh4Sfwbn3HTKeaArxx2v8jD4. (原因:缺少 CORS 标头“Access-Control-Allow-Origin”)。
HTTP 请求:
如果我在另一个选项卡中打开此请求,我将获得身份验证并重定向到ExternalLoginCallback。
PS:我正在使用AspNet.Security.OAuth.BattleNet并且我没有使用ASP.NET Core Identity进行身份验证(使用自定义逻辑)。