身份服务器:在ANGLE中登录和注销后重定向? [英] Identity Server: Redirect after login and logout in Angular?

查看:27
本文介绍了身份服务器:在ANGLE中登录和注销后重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个基于.NET Core的角度项目中使用了IdentityServer,并通过修改使用了Identity Server razor登录页面。除了这个登录页面,我使用角度页面,并使用角度中的延迟加载功能重定向相关页面。

但是,我需要一些不同的登录和注销场景,如下所述:

1.用户登录后,我希望重定向特定页面。我如何设置此页面?在标识服务器操作方法中,还是在登录按钮的onClick操作中?我也可以通过hperlink使用HREF?

2.我是否应该使用ActionLink等,因为登录页面是通过将页面重定向到控制器,然后打开一个角度页面来实现的?还是使用登录按钮的href或routerlink属性并轻松调用相关的角度路线更好?

3.对于注销,我希望重定向一个有角度的页面。我应该在标识服务器配置的注销或注销回调属性中设置它吗?

如有任何帮助,我们将不胜感激。

更新:以下是可用于重定向或回调设置的常量文件:

export const LogoutActions = {
  LogoutCallback: 'logout-callback',
  Logout: 'logout',
  LoggedOut: 'logged-out'
};

export const LoginActions = {
  Login: 'login',
  LoginCallback: 'login-callback',
  LoginFailed: 'login-failed',
  Profile: 'profile',
  Register: 'register'
};

let applicationPaths: ApplicationPathsType = {
  DefaultLoginRedirectPath: '/',
  ApiAuthorizationClientConfigurationUrl: `/_configuration/${ApplicationName}`,
  Login: `authentication/${LoginActions.Login}`,
  LoginFailed: `authentication/${LoginActions.LoginFailed}`,
  LoginCallback: `authentication/${LoginActions.LoginCallback}`,
  Register: `authentication/${LoginActions.Register}`,
  Profile: `authentication/${LoginActions.Profile}`,
  LogOut: `authentication/${LogoutActions.Logout}`,
  LoggedOut: `authentication/${LogoutActions.LoggedOut}`,
  LogOutCallback: `authentication/${LogoutActions.LogoutCallback}`,
  LoginPathComponents: [],
  LoginFailedPathComponents: [],
  LoginCallbackPathComponents: [],
  RegisterPathComponents: [],
  ProfilePathComponents: [],
  LogOutPathComponents: [],
  LoggedOutPathComponents: [],
  LogOutCallbackPathComponents: [],
  IdentityRegisterPath: '/Identity/Account/Register',
  IdentityManagePath: '/Identity/Account/Manage'
};

applicationPaths = {
  ...applicationPaths,
  LoginPathComponents: applicationPaths.Login.split('/'),
  LoginFailedPathComponents: applicationPaths.LoginFailed.split('/'),
  RegisterPathComponents: applicationPaths.Register.split('/'),
  ProfilePathComponents: applicationPaths.Profile.split('/'),
  LogOutPathComponents: applicationPaths.LogOut.split('/'),
  LoggedOutPathComponents: applicationPaths.LoggedOut.split('/'),
  LogOutCallbackPathComponents: applicationPaths.LogOutCallback.split('/')
};

身份

您要做的是将您的推荐答案客户端配置设置为通过<[2-1]和PostLogoutRedirectUris指向这些不同的组件。然后在ANGLE应用程序中,当您配置UserManager实例时,将redirect_uripost_logout_redirect_uri设置为您希望Identity Server在登录/注销方法完成后重定向到的位置。这些配置需要在客户端和服务器之间匹配,否则身份服务器将拒绝该请求。布罗克·艾伦的一个样例应用程序Angular oidc-client.js揭示了这一点。

配置完成后,重定向应该是自动的,您应该不需要在IdentityServer中修改重定向。这仅涵盖登录/注销流程。我看到你在角度应用中有注册和失败登录的定义。您可以做的是修改视图控制器以通过return Redirect("someurl oangularcomponent");将用户重定向到该组件。

这篇关于身份服务器:在ANGLE中登录和注销后重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆