Ionic framework 当IdentityServer重定向到重定向uri时Cors问题
我正在开发一个SPA web应用程序,包括:Ionic framework 当IdentityServer重定向到重定向uri时Cors问题,ionic-framework,asp.net-identity,identityserver4,Ionic Framework,Asp.net Identity,Identityserver4,我正在开发一个SPA web应用程序,包括: 在上运行的APIhttps://localhost:5001 正在上运行的IdentityServer 4https://localhost:5001 一个移动应用程序,使用API的客户端,运行在http://localhost:8100. 它基于离子+电容器,使用离子服务发射 我无法从手机完成登录流。现在起作用的是,移动应用程序调用identity server进行授权,identity server验证用户,结果应通过重定向返回到移动应用程序
- 在上运行的APIhttps://localhost:5001
- 正在上运行的IdentityServer 4https://localhost:5001
- 一个移动应用程序,使用API的客户端,运行在http://localhost:8100. 它基于离子+电容器,使用离子服务发射
- 移动应用程序使用代码流调用identity server授权端点
- Identity server将我重定向到交互式登录页面
- 我输入电子邮件/密码并调用web api进行身份验证
- 使用令牌和凭据的Identityserver调用/授权/回调
- 授权/回调应该将我重定向到移动应用程序的重定向uri (http://localhost:8100/authcallback),但是我得到的CORS问题如下,问题的原因可能是什么
[HttpPost("login")]
public async Task<IActionResult> Login(UserResource model) {
var result = await signInManager.PasswordSignInAsync(model.email, model.password, isPersistent: true, lockoutOnFailure: false);
var context = await interaction.GetAuthorizationContextAsync(model.return_url);
if (result.Succeeded) {
// @todo will need to be changed to support multiple organizations
var uo = db.Users.Include(q => q.UserOrganization).Single( q => q.Email == model.email ).UserOrganization.First();
uo.LastLogin = DateTime.UtcNow;
await db.SaveChangesAsync();
// let identity server know that we loggedin
await identityEvents.RaiseAsync(new UserLoginSuccessEvent(
model.email, uo.UserId, model.email, clientId: context?.Client.ClientId
));
return Redirect(model.return_url);
/*return Ok( new{
email = model.email,
return_url = context.RedirectUri
} );*/
}
// not including an empty object here raises an error, maybe a problem with core3-preview5
await identityEvents.RaiseAsync(new UserLoginFailureEvent(model.email, "invalid credentials", clientId:context?.Client.ClientId));
return NotFound(new {});
}
[HttpPost(“登录”)]
公共异步任务登录(用户资源模型){
var result=wait-signInManager.PasswordSignInAsync(model.email,model.password,ispersist:true,lockoutOnFailure:false);
var context=await interaction.GetAuthorizationContextAsync(model.return_url);
如果(result.succeed){
//@todo需要更改以支持多个组织
var uo=db.Users.Include(q=>q.UserOrganization).Single(q=>q.Email==model.Email).UserOrganization.First();
uo.LastLogin=DateTime.UtcNow;
等待db.saveChangesSync();
//让identity server知道我们登录了
等待identityEvents.RaiseAsync(新用户登录访问事件(
model.email,uo.UserId,model.email,clientId:context?.Client.clientId
));
返回重定向(model.return\uURL);
/*返回Ok(新的{
email=model.email,
return\u url=context.RedirectUri
} );*/
}
//此处不包含空对象会引发错误,可能是core3-preview5的问题
等待identityEvents.RaiseAsync(新用户登录失败事件(model.email,“无效凭据”,clientId:context?.Client.clientId));
返回NotFound(新{});
}
问题实际上是我发出了一个从XmlHttpRequest到另一个源的重定向(http://localhost:8100),所以chrome不会像那样给我这个错误
修复程序在signin控制器中返回Ok()而不是Redirect(),在javascript spa客户端中,我使用window.location执行重定向。问题实际上是我正在从XmlHttpRequest发出重定向到另一个来源(http://localhost:8100),所以chrome不会像那样给我这个错误 修复程序在signin控制器中返回Ok()而不是Redirect(),在javascript spa客户端中,我使用window.location执行重定向