十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
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); });
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。