大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
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); });