如果您不想刷新應用程序,則可以按照adal.js library更新id_token的方式在iframe中運行相同的代碼。
AuthenticationContext.prototype._renewIdToken = function (callback) {
// use iframe to try refresh token
this.info('renewIdToken is called');
var frameHandle = this._addAdalFrame('adalIdTokenFrame');
var expectedState = this._guid() + '|' + this.config.clientId;
this._idTokenNonce = this._guid();
this._saveItem(this.CONSTANTS.STORAGE.NONCE_IDTOKEN, this._idTokenNonce);
this.config.state = expectedState;
// renew happens in iframe, so it keeps javascript context
window.renewStates.push(expectedState);
this.verbose('Renew Idtoken Expected state: ' + expectedState);
var urlNavigate = this._getNavigateUrl('id_token', null) + '&prompt=none';
urlNavigate = this._addHintParameters(urlNavigate);
urlNavigate += '&nonce=' + encodeURIComponent(this._idTokenNonce);
this.registerCallback(expectedState, this.config.clientId, callback);
this.idTokenNonce = null;
this.verbose('Navigate to:' + urlNavigate);
frameHandle.src = 'about:blank';
this._loadFrameTimeout(urlNavigate, 'adalIdTokenFrame', this.config.clientId);
};
然而ng2-adal
庫不提供_renewIdToken
方法,如果你也想這個功能,你可以從its project site of GitHub提交反饋。