private async redirectOrVerifyToken()

in src/auth/ImplicitGrantStrategy.ts [45:72]


    private async redirectOrVerifyToken(): Promise<AccessToken> {
        const hashParams = new URLSearchParams(window.location.hash.substring(1));
        const accessToken = hashParams.get("access_token");

        if (accessToken) {
            return Promise.resolve({
                access_token: accessToken,
                token_type: hashParams.get("token_type") ?? "",
                expires_in: parseInt(hashParams.get("expires_in") ?? "0"),
                refresh_token: hashParams.get("refresh_token") ?? "",
                expires: Number(hashParams.get("expires")) || 0
            });
        }

        const scopes = this.scopes ?? [];
        var scope = scopes.join(' ');

        const params = new URLSearchParams();
        params.append("client_id", this.clientId);
        params.append("response_type", "token");
        params.append("redirect_uri", this.redirectUri);
        params.append("scope", scope);

        const authUrl = 'https://accounts.spotify.com/authorize?' + params.toString();

        this.configuration!.redirectionStrategy.redirect(authUrl);
        return emptyAccessToken;
    }