首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未使用oidc-client调用的静默重定向uri

未使用oidc-client调用的静默重定向uri
EN

Stack Overflow用户
提问于 2020-08-05 17:02:48
回答 1查看 3.2K关注 0票数 0

我们尝试使用Oidc-客户端库无声地更新令牌(刷新令牌)。我们成功登录了。但是,一旦用户的令牌过期,静默回调页就不会被调用,即使配置如下。如果有任何遗漏或重新纠正,请提供帮助。此外,静默重定向uri作为redirect_uri之一配置在标识服务器中。

Login.ts

代码语言:javascript
复制
Office.initialize = function () {  
     var settings = {
      authority: "https://xxxx.xxxxx.com/xxxx/v1", 
      client_id: "https://xxx.xxx.com/",
      redirect_uri: "https://localhost:3000/taskpane.html",
      post_logout_redirect_uri: "https://localhost:3000/logout.html", 
      revokeAccessTokenOnSignout: true,      
      response_type: "id_token token",
      scope: "openid read:xxxx read:xxxx",
      state: true,
      filterProtocolClaims: true,  
      loadUserInfo: true,
      nonce:true, 
      clearHashAfterLogin: true,
      automaticSilentRenew: true,     
      silent_redirect_uri: 'https://localhost:3000/silent-refresh.html',      
      monitorsession:true,  
      metadata: {        
        issuer: 'https://xxx.xxx.com/xxx/v1',                    
        authorization_endpoint:  "https://xxx.xxx.com/xxxxx/v1/connect/authorize"                  
       
    }    
    };
    
    var mgr = new Oidc.UserManager(settings);
    mgr.signinRedirect();
    
mgr.events.addAccessTokenExpiring(function(){
    console.log("token expiring...");
}); 

}

silent-refresh.html

代码语言:javascript
复制
<head>
    <title>RefreshToken</title>
    <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
</head>
<body>
    <script type="text/javascript" src=https://cdnjs.cloudflare.com/ajax/libs/oidc-client/1.10.0/oidc-client.js></script>
<script>
    new Oidc.UserManager().signinSilentCallback().then((user)=>
    { consolse.log("silentrenewed");}
    )
        .catch((err) => {
            console.log(err);
        });
        
</script>
</body>

Auth.ts

代码语言:javascript
复制
import { UserManager, WebStorageStateStore } from "oidc-client";

export default class AuthSigninService {
  private userManager: UserManager;

  constructor() {
  
      const settings: any = {
        ..................
        automaticSilentRenew: true,                                        
      accessTokenExpiringNotificationTime: 4,   
        silent_redirect_uri: "https://localhost:3000/taskpane.html",      
        monitorsession:false,  
             };

      this.userManager = new UserManager(settings);
    }
    
    public signin()
    {
        return this.userManager.signinRedirect();
    }  

      
  public async silentRenew() {
    try {
      const user = await this.userManager.signinSilentCallback().then((success) => {
        console.log("silentrenewed");
        console.log(success);
      }
      )
        .catch((err) => {
          console.log(err);
        });

    }
    catch (err) {
      console.log(err);
    }
    } 
}

taskpane.ts

代码语言:javascript
复制
document.getElementById('btnSilent').onclick = SilentRenew;

async function SilentRenew() {

  const auth = new AuthSigninService();
  auth.silentRenew();
   
}
EN

回答 1

Stack Overflow用户

发布于 2020-08-05 22:05:31

可能的原因:

  • 与内联脚本有关
  • 也许UserManager的第二个实例也需要使用设置进行初始化。

,我会尝试什么,

  • 在主窗口上,调用等待mgr.signInSilent();执行“随需应变”的无声更新,并查看是否得到任何console.log输出。
  • 使iframe代码成为您的主要应用程序的一部分,而不是在HTML页面中内联运行它

比较的东西

我的代码样本做如果沉默更新和水疗代码可能会给你一些想法。

我倾向于将无声的更新URI设置为主index.html页面,这比较简单。然后编写如下代码:

代码语言:javascript
复制
if (window.top === window.self) {

    // If index.html is running on the main window, run the app
    const app = new App();
    app.execute();

} else {
  
    // If index.html is running on an iframe, handle token renewal responses
    const app = new IFrameApp();
    app.execute();

}

顺便说一下,这是我的OAuth代码

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63270087

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档