我正在尝试在我的 Angular SPA 中静默刷新访问令牌。针对 ADFS 的身份验证已完成。它工作正常,配置如下:
oauthService.configure({
redirectUri:
window.location.origin + '/login',
requireHttps: true,
scope: 'openid profile email',
responseType: 'id_token token',
oidc: true,
clientId: environment.adfsClientId,
loginUrl: environment.adfsUrl + '/oauth2/authorize',
issuer: environment.adfsUrl,
logoutUrl:
environment.adfsUrl +
'/ls/?wa=wsignoutcleanup1.0&wreply=' +
location.protocol +
'//' +
location.hostname + '/login',
postLogoutRedirectUri:
window.location.origin + '/login',
});
this.oauthService.tokenValidationHandler = new JwksValidationHandler();
this.oauthService.setStorage(localStorage);
this.oauthService.timeoutFactor = 0.03; // for faster testing
this.oauthService.silentRefreshRedirectUri = window.location.origin + '/search';
this.oauthService.setupAutomaticSilentRefresh();
为了刷新令牌,iframe 被添加到当前页面。一切看起来都很好。我已将以下代码添加到 index.html 文件中。
<script>
parent.postMessage(location.hash, location.origin);
</script>
此事件在 silentRefreshPostMessageEventListener 的 angular-oauth2-oidc.js 中被捕获。但问题是我在那个列表中得到的信息是,
MSIS9621:无法在未获得用户输入的情况下处理 OAuth 授权请求。
在 iframe 中生成的 src 标签值如下所示,
https://[adfs domain]/adfs/oauth2/authorize/?response_type=id_token%20token&client_id=af0e4d79-ae9d-4fda-86b3-265d1e86a61e&state=UmtkeUJfNDBCUU1VWkZyeWcubFlldlo3ZHFFbFRuVDI3TnNZUU5FVXJxTXpX&redirect_uri=http%3A%2F%2Flocalhost%3A4200%2Fsearch&scope=openid%20profile% 20email&nonce=UmtkeUJfNDBCUU1VWkZyeWcubFlldlo3ZHFFbFRuVDI3TnNZUU5FVXJxTXpX&prompt=none
如果我在新选项卡中打开此 URL,我会在 Uri 中获得一个新的访问令牌。
谁能告诉我我在这里做错了什么?
更新
谢谢,加里·阿切尔的回答。
我通过在 PowerShell 中执行此代码对 ADFS 进行了更改,
Set-AdfsResponseHeaders -RemoveHeaders "X-Frame-Options"
没有改变。然后我设置下面的命令来解决这个问题。
Set-AdfsResponseHeaders -SetHeaderName "Content-Security-Policy" -SetHeaderValue "frame-ancestors < 来源 >"