login dialogue fails to trigger in Auth09 when manifest has different origin
UV version:
[email protected]
I'm submitting a:
- [x] bug report
- [ ] feature request => please use the user stories repo
- [ ] support request => Please do not submit support requests here, use stackoverflow
Current behavior:
When authentication version 0.9 is in effect, and is loaded from a different origin, then the login dialogue fails to trigger:
Failed to load resource: the server responded with a status of 401 (Unauthorized)
14:12:59.679 UVComponent.js:163 Uncaught (in promise) TypeError: Cannot read property 'publish' of undefined
at Function.UVComponent.publish (UVComponent.js:163)
at Auth09.js:65
at new Promise (<anonymous>)
at Auth09.login (Auth09.js:59)
at Function.Utils.showAuthInteraction (manifesto.js:3017)
at manifesto.js:2971
I did some debugging, and I saw that the this in UVComponent.prototype.publish
is called by Auth09.publish, which of course set that this to Auth09, that
does not have an object _pubsub.
I tried to reset the function in the constructor of BaseExtension:
Auth09_1.Auth09.publish = function(){ _this.component.publish(arguments); };
but without any effect
Expected behavior:
Steps to reproduce:
- Use manifest https://adore.ugent.be/IIIF/manifests/archive.ugent.be%3A8F9A1D26-0C03-11E6-86D8-4B5BF264C48D
- Set
options.authAPIVersionto 0.9
// insert any relevant code here
Other information:
It starts to work if I change these lines (https://github.com/UniversalViewer/universalviewer/blob/master/src/modules/uv-shared-module/BaseExtension.ts#L53)
Auth09.publish = this.component.publish;
Auth1.publish = this.component.publish;
to
Auth09.publish = function(){ that.component.publish.apply(that.component,arguments); };
Auth1.publish = function(){ that.component.publish.apply(that.component,arguments); };
and in https://github.com/UniversalViewer/universalviewer/blob/master/src/modules/uv-dialogues-module/LoginDialogue.ts#L31
the argument e becomes an array:
this.component.subscribe(this.openCommand, (e: any) => {
this.loginCallback = e[0].loginCallback;
this.logoutCallback = e[0].logoutCallback;
this.options = e[0].options;
this.resource = e[0].resource;
this.open();
});
Not sure if this breaks other stuff
@nicolasfranck I've put a PR that should fix the issue: https://github.com/UniversalViewer/universalviewer/pull/687 based on the fix you found to work
@stephenwf now this equals Extension, instead of UVComponent when UVComponent.prototype.publish is called (add a log statement to see this).
Changing bind(this) to bind(this.component) fixes part of the problem.
But then resource of LoginDialogue is undefined. See fix above.
hmm yes I see what you mean.
Same goes for:
- https://github.com/UniversalViewer/universalviewer/blob/master/src/modules/uv-dialogues-module/AuthDialogue.ts#L29 : argument
eis an array, but is used as an object - https://github.com/UniversalViewer/universalviewer/blob/master/src/modules/uv-shared-module/HeaderPanel.ts#L130 : argument
argsis an array, but is used as an object
All issues will be triaged for further investigation or closure by the 28 September 2023. If your issue is still relevant and would like for it be investigated further please comment by 14 September 2023.