我有一个与oidc客户端进行身份验证的Angular应用程序,而且代码在Chrome和Edge上工作正常,但是当我尝试使用Safari进行身份验证时,它会在多次重试/错误后运行,而使用Firefox则无法正常工作。我得到的错误是:
Error: Uncaught (in promise): Error: No matching state found in storage
x</t.prototype.processSigninResponse/<@webpack-internal:///../../../../oidc-client/lib/oidc-client.min.js:1:5057
ZoneDelegate.prototype.invoke@webpack-internal:///../../../../zone.js/dist/zone.js:388:17
onInvoke@webpack-internal:///../../../core/esm5/core.js:4947:24
ZoneDelegate.prototype.invoke@webpack-internal:///../../../../zone.js/dist/zone.js:387:17
Zone.prototype.run@webpack-internal:///../../../../zone.js/dist/zone.js:138:24
scheduleResolveOrReject/<@webpack-internal:///../../../../zone.js/dist/zone.js:858:52
ZoneDelegate.prototype.invokeTask@webpack-internal:///../../../../zone.js/dist/zone.js:421:17
onInvokeTask@webpack-internal:///../../../core/esm5/core.js:4938:24
ZoneDelegate.prototype.invokeTask@webpack-internal:///../../../../zone.js/dist/zone.js:420:17
Zone.prototype.runTask@webpack-internal:///../../../../zone.js/dist/zone.js:188:28
drainMicroTaskQueue@webpack-internal:///../../../../zone.js/dist/zone.js:595:25
Stack trace:
resolvePromise@webpack-internal:///../../../../zone.js/dist/zone.js:809:31
resolvePromise@webpack-internal:///../../../../zone.js/dist/zone.js:775:17
scheduleResolveOrReject/<@webpack-internal:///../../../../zone.js/dist/zone.js:858:17
ZoneDelegate.prototype.invokeTask@webpack-internal:///../../../../zone.js/dist/zone.js:421:17
onInvokeTask@webpack-internal:///../../../core/esm5/core.js:4938:24
ZoneDelegate.prototype.invokeTask@webpack-internal:///../../../../zone.js/dist/zone.js:420:17
Zone.prototype.runTask@webpack-internal:///../../../../zone.js/dist/zone.js:188:28
drainMicroTaskQueue@webpack-internal:///../../../../zone.js/dist/zone.js:595:25
在我看来,它必须采用浏览器管理存储的方式,但我不确定这是否还有其他问题。我有的版本:
"@angular/animations": "5.2.1",
"@angular/common": "5.2.1",
"@angular/compiler": "5.2.1",
"@angular/core": "5.2.1",
"@angular/forms": "5.2.1",
"@angular/http": "5.2.1",
"@angular/platform-browser": "5.2.1",
"@angular/platform-browser-dynamic": "5.2.1",
"@angular/platform-server": "5.2.1",
"@angular/router": "5.2.1",
"@ng-bootstrap/ng-bootstrap": "1.0.0",
"@nguniversal/express-engine": "5.0.0-beta.5",
"@nguniversal/module-map-ngfactory-loader": "5.0.0-beta.5",
"bootstrap": "4.0.0-beta.2",
"core-js": "2.5.3",
"font-awesome": "4.7.0",
"oidc-client": "1.4.1",
"rxjs": "5.5.6",
"zone.js": "0.8.20"
处理身份验证回调的代码非常简单:
completeAuthentication(): Promise<void> {
if (isPlatformBrowser(this.platformId)) {
return this.manager.signinRedirectCallback()
.then(user => {
this.user = user;
});
}
}
其中manager
是UserManager
个实例:
@Injectable()
export class AuthService {
private manager: UserManager;
private user: User = null;
constructor(@Inject(PLATFORM_ID) private platformId: Object) {
if (isPlatformBrowser(platformId)) {
this.manager = new UserManager(getClientSettings());
this.manager.getUser().then(user => {
this.user = user;
});
}
为什么相同的代码在不同的浏览器上失败的任何想法?
答案 0 :(得分:1)
我意识到我正在独立于实际的completeAuthentication()
承诺执行重定向,因此我失败了。我只是将它添加到then
上,一切都很顺利。