Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

afterRefreshCheck infinitely called #265

Open
W1nstar opened this issue Jul 17, 2019 · 7 comments
Open

afterRefreshCheck infinitely called #265

W1nstar opened this issue Jul 17, 2019 · 7 comments

Comments

@W1nstar
Copy link

W1nstar commented Jul 17, 2019

We've been trying to set up a SSO driven JSDO project, but we can't past the fact it hangs on the afterRefreshCheck.

It can login no problem, any CRUD operation is working as expected, but after the token is expired out, the JSDO class tries to refresh it and enters an infinite loop.

We've tried to set this up by ourselves using the scarce documentation we could find on PASOE related SSO. We couldn't find any documentation at all on JSDO with SSO.

Any help would be welcome.

This is how we login on the system:

const auth = new progress.data.AuthenticationProviderSSO(serviceURI);

const options = {
    serviceURI: serviceURI,
    authenticationModel: progress.data.Session.AUTH_TYPE_SSO,
    authProvider : auth
};

console.log(auth);

if (!auth._loggedIn) {
	auth.login("walter","walter").then((e) => {
		const jsdoSession = new progress.data.JSDOSession(options);

		jsdoSession.addCatalog(	[catalogURI, 'http://192.10.10.29:8810/web/web/catalog/jsdo/lineasInventarios']).then(data => {
			console.log(data)
			jsdo = new progress.data.JSDO({ name: 'paises' })
			readRecords()
		})
		
	})
	.catch((e)=> console.log(e));
} else {
	const jsdoSession = new progress.data.JSDOSession(options);

	jsdoSession.addCatalog(	[catalogURI, 'http://192.10.10.29:8810/web/web/catalog/jsdo/lineas']).then(data => {
		console.log(data)
		jsdo = new progress.data.JSDO({ name: 'paises' })
		readRecords()
	})
}

After the token has expired, this is the callstack we're facing:

the callstack
this is how it starts

Like I said, we're doing this by ourselves so any help would be appreciated.

Thanks in advance, and apologies if this is common knowledge but we're just beign dumb.

@W1nstar
Copy link
Author

W1nstar commented Jul 17, 2019

I might have found the culprit, but I lack enought comprehension of the whole JSDO to say if it's ok.

I'd still like to know what do you guys think! I'm not enterely sure of what I'm doing!

When the AuthenticationProviderSSO is created, there's this piece of code about credentials that is seemingly rewriting a callback, thus creating the infinite loop. If I rename that var, it all seems to work. It refreshes as expected, or at least it seems so. This is the piece of code:

            if (this.hasClientCredentials()) {
                // Every token given has an expiration "hint". If the token's lifespan
                // is close to or past that limit, then a refresh is done.
                // No matter what the outcome of the refresh, keep in mind we always 
                // send the original request.
                date = new Date();
                if (this.automaticTokenRefresh &&
                    this.hasRefreshToken() &&    
                    date.getTime() > retrieveAccessTokenExpiration()) {
                    try {
                        var callback_mks = function (params, result, info) { //RENAMING THIS FROM callback to callback_mks SORRY
                            params = progress.util.Deferred.getParamObject(params, result, info);
                            afterRefreshCheck(params.provider, params.result, params.info);
                        };
                        // finally
                        this.refresh()
                            .then(callback_mks, callback_mks); //CALLING MY RENAMED VAR DON'T MIND ME
                    } catch (e) {
                        callback_mks(e); //MORE RENAMING
                    }
                } else {
                    afterRefreshCheck(this, progress.data.Session.SUCCESS, null);
                }
            } else {
                // This message is SSO specific, unless we can come up with a more general message 
                // JSDOSession: The AuthenticationProvider needs to be managing a valid token.
                errorObject = new Error(progress.data._getMsgText("jsdoMSG125", "AuthenticationProvider"));
                callback(errorObject);
            }

I hope someone could help me.

@joshualan
Copy link
Collaborator

Hey, @W1nstar, the JSDO unfortunately does not officially support SSO.... though if we have enough interest, i can definitely bring this up as something we can officially support.

I think that we might've accidentally brought us into callback hell where the name callback got overloaded, causing it to go into a loop?

You might just write jsdosession.automaticTokenRefresh = false; to temporarily get aroundthis and manually call refresh() every now and then for now.

I'll try to take a look tomorrow

@W1nstar
Copy link
Author

W1nstar commented Jul 19, 2019

Thanks a lot for the response. You really made my day! I look forward your help.

The callback hell might be real. With the change I did works, but sometimes errors somewhere else, so I guess I'm not on the right track there. I tried to personally look into this, and my goal was to make you guys a PR, but as I said I lack knowledge on most themes going on here to help you. I'll need a few days to be able to look at it, but I will try. We're trying to avoid a manual refresh.

We were under the impression it was supported since it seemed to have everything needed inside, plus we saw advertising on progress's learning courses about pasoe, jsdo and SSO. It's a bummer it's not supported officially. Is there any way we can express our interest more officially?

Thank you again for your feedback, @joshualan .

@W1nstar
Copy link
Author

W1nstar commented Nov 20, 2019

Any news on this issue, @joshualan ? I was able to stop the infinite loop, but now we have found there's an unhandled exception (

throw arg;
it even has "we have to fix this" comment) when the token is rejected, that is proving very difficult for us to fix it without full knowledge of what's going on. I've already spent a full day trying things, but nothing seems to work.
Edit: forgot to say, the unhandled exception is not a part of sso, it's on the general _openRequest.

@joshualan
Copy link
Collaborator

@W1nstar we're throwing something in the backlog for this so we might have time to look into this in the next few months but we judge the amount of interest in the project via pull requests.

Sorry for the late reply, was on vacation for a while.

Is the same original code causing this issue?

@W1nstar
Copy link
Author

W1nstar commented Dec 17, 2019

@joshualan yeah, on the original code there's still the infinite loop plus the _openRequest throw arg.

@seankupiec
Copy link

This fix was the same as mine as well. The deceleration of "callback" inside _openRequestAndAuthorize function caused a loop from afterRefreshCheck at line 291. Updating line 308 and 314 corrects this issue and successfully refreshes the token and continues the original request in our project.

@edselg Do you think we can get the pull request #276 pushed into the live branch for others to be able to use it (including our other projects)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants