amazon-cognito-auth-js icon indicating copy to clipboard operation
amazon-cognito-auth-js copied to clipboard

Integration with Single Page Applications

Open rafalwrzeszcz opened this issue 7 years ago • 0 comments

Is there any way to integrate authentication flow with a SPA (no page reloads)? I've managed to create some simple wrapper which opens authentication window:

import { CognitoAuth, CognitoAuthOptions } from "amazon-cognito-auth-js/dist/amazon-cognito-auth";

export class SpaCognitoClient extends CognitoAuth {
    private popup: Window;

    constructor(options: CognitoAuthOptions) {
        super(options);

        window.addEventListener("message", this.handleResponse, false);
    }

    protected launchUri(url: string): void {
        this.popup = window.open(url);
    }

    private handleResponse = (event: MessageEvent): void => {
        if (typeof(event.data) === "object" && "event" in event.data && event.data.event === "authSuccess") {
            this.popup.close();
            this.parseCognitoWebResponse(event.data.hash);
        }
    }
}

But this only works when user clicks the button. I can't find any way to implement "silent" token refresh, as opening sign-in page in background is blocked as a pop-up.

It's also not possible to embed the sign-in page in the IFRAME because of X-Frames DENY policy.

Is there any other call/endpoint that can be used to obtain new token?

rafalwrzeszcz avatar Aug 15 '18 11:08 rafalwrzeszcz