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

[Question]: Redirected to callback url with code parameter but no session token is retrieved #2053

Open
jjwmenting opened this issue Dec 12, 2024 · 2 comments
Labels

Comments

@jjwmenting
Copy link

jjwmenting commented Dec 12, 2024

What Version of the library are you using?
v17.1.0

Question
I have implemented the flow for AWS Cognito as my identity provider. When i try to call the .authorize() function i get redirected to the AWS Cognito login pages as expected. After i login i get redirected to the provided callback URL with the code query parameter but the library keeps telling me i am not authenticated, from my understanding there should have been another call to AWS Cognito to retrieve an access token based on the code given in the callback URL.

I have created a clean Angular v17 without SSR application and included the bare minimum quick start code but the same problem occurs when trying to authenticate. Am i missing something which retrieves the access token from AWS Cognito?

EDIT: Some extra information; after logging in the code authorization seems to be happening and i enter public event type 7 which indicates i am authenticated but .checkAuth() function keeps saying isAuthenticated: false and i can't get a token.

@RedSerenity
Copy link

Did you figure this out? I'm running into the same issue. I've tried v18.0.2 and v19.0.0. Same problem.

@origooo
Copy link

origooo commented Jan 14, 2025

For me this issue was solved by correcting the config.redirectUrl. I had accidentally told our IdP to add our URLs with a trailing slash. I guess without trailing slashes are the standard, but I was clumsy while handing over our URLs.

In version 17 of this library, the UrlService.isCallbackFromSts() looks like the following:

isCallbackFromSts(currentUrl) {
    return CALLBACK_PARAMS_TO_CHECK.some((x) => !!this.getUrlParameter(currentUrl, x));
}

In newer versions it looks as follows:

isCallbackFromSts(currentUrl, config) {
    if (config && config.checkRedirectUrlWhenCheckingIfIsCallback) {
        const currentUrlInstance = new URL(currentUrl);
        const redirectUrl = this.getRedirectUrl(config);
        if (!redirectUrl) {
            this.loggerService.logError(config, `UrlService.isCallbackFromSts: could not get redirectUrl from config, was: `, redirectUrl);
            return false;
        }
        const redirectUriUrlInstance = new URL(redirectUrl);
        const redirectUriWithoutQueryParams = this.getUrlWithoutQueryParameters(redirectUriUrlInstance).toString();
        const currentUrlWithoutQueryParams = this.getUrlWithoutQueryParameters(currentUrlInstance).toString();
        const redirectUriQueryParamsArePresentInCurrentUrl = this.queryParametersExist(redirectUriUrlInstance.searchParams, currentUrlInstance.searchParams);

        // PROBLEMATIC ROW BELOW, BUT PRESUMABLY 100% CORRECT
        // PROBLEMATIC ROW BELOW, BUT PRESUMABLY 100% CORRECT
        if (redirectUriWithoutQueryParams !== currentUrlWithoutQueryParams ||
            !redirectUriQueryParamsArePresentInCurrentUrl) {
            return false;
        }
    }
    return CALLBACK_PARAMS_TO_CHECK.some((x) => !!this.getUrlParameter(currentUrl, x));
}

The issues was simply that the current URL doesn't include a trailing slash like the config.redirectURL had. I presume this is correct.

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

No branches or pull requests

3 participants