B2C嵌入式登录体验
B2C Embedded sign-in experience
我按照指南使用 b2c 和 IFrame (Embedded Sign-In Doc) 设置了嵌入式登录体验。
但是,我不太确定如何获取访问令牌并在我的整个应用程序中使用它。
到目前为止,我得到了 IFrame 来显示 SignIn/SignUp 表单,并且 login/signup 工作完美。
但之后 IFrame 重定向到应用程序的登录页面,我的“父”页面没有收到 ID 令牌。
(“父”页面的 url 匹配 iframe 授权请求的重定向 url)
IFrame 的 src 是我的 b2c 策略的授权请求url。
PS:查看网络选项卡我可以在“已确认”响应中看到颁发的有效 ID 令牌(重定向-url/#id_token=eyJ0eX... ) 来自 b2c 政策。
最佳
最大值
这就是文档中指示使用 window.top.location.reload() 的原因;以便页面在登录完成后重新加载,您可以在页面逻辑中正常捕获 id 令牌。
例如,您可以在布局中使用以下脚本:
<!-- Because the authorization flow happens inside the iframe, we need to reload the main page.-->
<script>
if (document.referrer.startsWith('@Configuration.GetSection("AzureAdB2C")["Instance"]'))
window.top.location.reload();
</script>
另一种方法是,您可以将登录请求的重定向 url 设置为“LoginCompleted”页面,并让它为您进行重定向。
这里有几个使用预建样本的例子:
- (.netcore, 使用重定向脚本) https://github.com/helshabini/active-directory-aspnetcore-webapp-openidconnect-v2/tree/master/1-WebApp-OIDC/1-7-B2C-Embedded
- (.net框架,使用登录完成页面)https://github.com/azure-ad-b2c/sign-in-with-iframe
- (nodejs,使用重定向脚本)https://github.com/techjazz-MS/B2C_EmbeddedSignin_nodejs_passportjs_Sample
我按照指南使用 b2c 和 IFrame (Embedded Sign-In Doc) 设置了嵌入式登录体验。
但是,我不太确定如何获取访问令牌并在我的整个应用程序中使用它。 到目前为止,我得到了 IFrame 来显示 SignIn/SignUp 表单,并且 login/signup 工作完美。 但之后 IFrame 重定向到应用程序的登录页面,我的“父”页面没有收到 ID 令牌。
(“父”页面的 url 匹配 iframe 授权请求的重定向 url)
IFrame 的 src 是我的 b2c 策略的授权请求url。
PS:查看网络选项卡我可以在“已确认”响应中看到颁发的有效 ID 令牌(重定向-url/#id_token=eyJ0eX... ) 来自 b2c 政策。
最佳 最大值
这就是文档中指示使用 window.top.location.reload() 的原因;以便页面在登录完成后重新加载,您可以在页面逻辑中正常捕获 id 令牌。
例如,您可以在布局中使用以下脚本:
<!-- Because the authorization flow happens inside the iframe, we need to reload the main page.-->
<script>
if (document.referrer.startsWith('@Configuration.GetSection("AzureAdB2C")["Instance"]'))
window.top.location.reload();
</script>
另一种方法是,您可以将登录请求的重定向 url 设置为“LoginCompleted”页面,并让它为您进行重定向。
这里有几个使用预建样本的例子:
- (.netcore, 使用重定向脚本) https://github.com/helshabini/active-directory-aspnetcore-webapp-openidconnect-v2/tree/master/1-WebApp-OIDC/1-7-B2C-Embedded
- (.net框架,使用登录完成页面)https://github.com/azure-ad-b2c/sign-in-with-iframe
- (nodejs,使用重定向脚本)https://github.com/techjazz-MS/B2C_EmbeddedSignin_nodejs_passportjs_Sample