如何在当前 Web 应用程序的 iframe 中使用有效令牌?

MHS*_*MHS 1 javascript openid-connect

我有两个 Web 应用程序(应用程序 A 和应用程序 B),并且想将其中一个(A)用作另一个(B)中的 iframe。我在当前的 Web 应用程序 (B) 中有一个令牌,它在 iframe (A) 中也有效。iframe Web 应用程序 (A) 使用 OIDC js 身份验证和 angularjs,现在如何将令牌从 B 发送到 A 并使用它?

在我的 A 应用程序中,我有这个:

var config = {
    authority: '...my auth server ...',
    client_id: '...'
    ...
}

mgr = new OidcTokenManager(config);

if (window.location.hash && window.location.hash.indexOf('id_token') > -1) {
    mgr.processTokenCallbackAsync().then(function () {
        //checkSessionState();
    }, function (error) {
    });
}
Run Code Online (Sandbox Code Playgroud)

这工作正常,但是当我使用 A 作为 iframe 时,mgr没有启动正确的和一些access_token未定义的属性!

小智 5

使用 Javascript 函数从 A => B => A 发布数据

来自 Parrent 应用程序 javascript 代码

 document
      .querySelector(`iframe`)
      .contentWindow.postMessage({ token: '112121' }, "*");
Run Code Online (Sandbox Code Playgroud)

接收器或 iframe 应用程序代码

window.addEventListener('message', receiveToken,*);

const receiveToken = message => {
    if (message.data && message.data.token){
        console.log(message.data.token)
   }
Run Code Online (Sandbox Code Playgroud)