universalviewer icon indicating copy to clipboard operation
universalviewer copied to clipboard

login dialogue fails to trigger in Auth09 when manifest has different origin

Open nicolasfranck opened this issue 6 years ago • 5 comments

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.authAPIVersion to 0.9
// insert any relevant code here

Other information:

nicolasfranck avatar Aug 19 '19 12:08 nicolasfranck

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 avatar Aug 19 '19 13:08 nicolasfranck

@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 avatar Aug 19 '19 13:08 stephenwf

@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.

nicolasfranck avatar Aug 19 '19 14:08 nicolasfranck

hmm yes I see what you mean.

stephenwf avatar Aug 19 '19 14:08 stephenwf

Same goes for:

  • https://github.com/UniversalViewer/universalviewer/blob/master/src/modules/uv-dialogues-module/AuthDialogue.ts#L29 : argument e is an array, but is used as an object
  • https://github.com/UniversalViewer/universalviewer/blob/master/src/modules/uv-shared-module/HeaderPanel.ts#L130 : argument args is an array, but is used as an object

nicolasfranck avatar Feb 20 '20 10:02 nicolasfranck

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.

LlGC-szw avatar Aug 25 '23 11:08 LlGC-szw