IdentityServer4 登录成功后,跳转到原来页面

发布时间:2020-06-11 20:17:15 作者:林羽恒
来源:网络 阅读:735

IdentityServer4 登录成功后,默认会跳转到Config.Client配置的RedirectUris地址http://localhost:5003/callback.html,用于获取 Token,比如跳转后的地址:

http://localhost:5003/callback.html#id_token=eyJhbGciOiJSUzI1NiIsImtpZCI6IjkwYWRmOTliMDhmODExMjBiMzdlMWI1NzVmMDliODcwIiwidHlwIjoiSldUIn0.eyJuYmYiOjE0OTQ2NjA3ODQsImV4cCI6MTQ5NDY2MTA4NCwiaXNzIjoiaHR0cDovL2xvY2FsaG9zdDo1MDAxIiwiYXVkIjoiaDUiLCJub25jZSI6IjQ0OTYwZDQzYjgwNTQzOWJiYjI4NWFkZjJiYjFkNDA0IiwiaWF0IjoxNDk0NjYwNzg0LCJhdF9oYXNoIjoieE9Lb0V1VnlMNHdXUVhsbllaak5udyIsInNpZCI6ImMzYzZkZjhhOTBjYjA3NGJhMWE4YjZjMzgzM2E5OTEwIiwic3ViIjoiMiIsImF1dGhfdGltZSI6MTQ5NDY2MDc4MywiaWRwIjoibG9jYWwiLCJhbXIiOlsicHdkIl19.AUNbgEoIOdw7_4NB9Hju-npbqWtqbytLe9uPhXuCwJwAbTeSIvHM3hE9ksqUCUIZtR8zYKYrCzUmHvqoZWvOEautxY9sJToPyyFeuuf7eKe5pgaplNFu6M3J8QBN9XRuGhYhipc-Yd3pa1zNmKAPC3yQbo_x139cBWIWHMIOkGxgW7IOcdrNvEB0Dq29tXcrUiOZkeOYC9sP_lLAhWA6_TeVXaJdwQ0vZQRtF7JaQ-Zt2yiFDhu2r3walhtg6AnCMnDVovyz1Vl--j-lANYkuprI-Zyzak-Cps-tT6_JC9sm8OIqVg_aK2t71AWg4dYAfgzYl_3_-N46OiOg8I-p5g&access_token=eyJhbGciOiJSUzI1NiIsImtpZCI6IjkwYWRmOTliMDhmODExMjBiMzdlMWI1NzVmMDliODcwIiwidHlwIjoiSldUIn0.eyJuYmYiOjE0OTQ2NjA3ODQsImV4cCI6MTQ5NDY2MDc5NCwiaXNzIjoiaHR0cDovL2xvY2FsaG9zdDo1MDAxIiwiYXVkIjpbImh0dHA6Ly9sb2NhbGhvc3Q6NTAwMS9yZXNvdXJjZXMiLCJhcGkxIl0sImNsaWVudF9pZCI6Img1Iiwic3ViIjoiMiIsImF1dGhfdGltZSI6MTQ5NDY2MDc4MywiaWRwIjoibG9jYWwiLCJuYW1lIjoiMTIzIiwibmljayI6Iuifi-ifgCIsIm1vYmlsZSI6IjE4NjU4MTMwMzI2Iiwic2NvcGUiOlsib3BlbmlkIiwicHJvZmlsZSIsImFwaTEiXSwiYW1yIjpbInB3ZCJdfQ.lOw-ZLnYt5VejRmh3JnQfL6q2z8T9iLQELUJv4v3vvOkIn5wmUDmhLWkS6GQFXaKwybKCQwlh7OOtb08WZyE-ID7TJS1to7ZqxFR0Q8AGmvsaQxQ2pRTsLcHj11mxdbYhekTxfUldlYYYklupXOCJRe64ioMszpgrwDW1-oepsoUSws9X3yAvwf4rMigZ93-_FMzhfQHBoP2v3vu4x0mRrcas4sX1JIOasBGcTLAttO3HuNHAKrsDZfpxnzhyUZpdmpwGdZEz4pboUIhnh0338BM-WHBCWBzRGtT1CMiqECXhFtbRzNjASlG3jsRXwRSeq7_PvXZmShWHCnkgnYGnw&token_type=Bearer&expires_in=10&scope=openid%20profile%20api1&state=22bdd1faeb21414b8071c915e696fe7a&session_state=lXXBM8MVyOwEPMf_nuzDtafYVsHGmGAJTRfDpGgAmKg.deb0cdd03489a8d0782577e162ceb67f

前端会从 URL 中获取到 Token 信息,然后把用户信息和 Token 写入到上下文中,示例代码:

new Oidc.UserManager().signinRedirectCallback().then(function () {
    window.location = "/index.html";
}).catch(function (e) {
    console.error(e);
});

可以看到,登录成功后,是手动设置的跳转地址,那我们该如何调整到登录之前的地址呢?其实也很简单(但我尝试了好久)就是使用state传递地址。

登录示例代码:

function login() {
    mgr.signinRedirect({ state: window.location.href });
}

callback.html登录成功后,回调示例代码:

new Oidc.UserManager().signinRedirectCallback().then(function (user) {
    window.location = user.state;
}).catch(function (e) {
    console.error(e);
});


推荐阅读:
  1. 怎么将Claims授权与自定义IdentityServer4 QuckStart
  2. IdentityServer4如何实现.Net Core API接口权限认证

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

token localhost 转到

上一篇:收藏~软件测试相关工具汇总

下一篇:loadrunner自学以及问题解答2

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》