private async exchangeIdToken()

in src/services/aadService.ts [26:56]


    private async exchangeIdToken(idToken: string, provider: string): Promise<void> {
        const credentials = `${provider} id_token="${idToken}"`;
        const userId = await this.usersService.authenticate(credentials);

        if (!userId) { // User not registered with APIM.
            const jwtToken = Utils.parseJwt(idToken);
            const firstName = jwtToken.given_name;
            const lastName = jwtToken.family_name;
            const email = jwtToken.email || jwtToken.emails?.[0];

            if (firstName && lastName && email) {
                await this.usersService.createUserWithOAuth(provider, idToken, firstName, lastName, email);
            }
            else {
                const signupUrl = this.routeHelper.getIdTokenReferenceUrl(provider, idToken);
                await this.router.navigateTo(signupUrl);
                return;
            }
        }

        const hash = this.router.getHash()
        let returnUrl = this.routeHelper.getQueryParameter("returnUrl") || Constants.pageUrlHome;

        if (hash) { // special case for server-side redirect when hash part of URL gets discarded
            returnUrl += `#${hash}`;
        }

        this.router.getCurrentUrl() === returnUrl
            ? location.reload()
            : await this.router.navigateTo(Utils.sanitizeReturnUrl(returnUrl));
    }