Chrome extension implicit grant flow trouple

I’m having trouble getting the twitch api to return the redirect URL. Currently, I’m trying to use chrome.identity to handle this.
my current code:

const redirectUri = chrome.identity.getRedirectURL();

chrome.identity.launchWebAuthFlow({
    'url': `https://id.twitch.tv/oauth2/authorize?client_id=${clientId}&redirect_uri=${redirectUri}&response_type=token&scope=user:read:follows`,
    'interactive': true
}, function(redirectUrl) {
    if (redirectUrl && redirectUrl.match(/access_token=([^&]+)/)) {
        const userAccessToken = redirectUrl.match(/access_token=([^&]+)/)[1];
    } else {
        console.error('redirectUrl error');
        console.log(redirectUrl);
    }
    chrome.storage.local.set({userAccessToken: userAccessToken}, function() {
        console.log('User access token is stored');
    });
});

Currently, the callback function for chrome.identity.launchWebAuthFlow() is not receiving the redirectUrl, so It’s being logged as undefined. The authorization/login page pops up correctly but it says it will redirect to localhost. Is my auth url correct?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.