0

我正在尝试在 google chrome 扩展中开发登录 OAuth 系统,尽管如此,当我尝试从回调中获取响应时,主窗口已经消失。

// 背景.js

chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
    if (request.message === 'login') {
        console.log("Login success - ");
        user_signed_in = true;
        sendResponse('success');


        chrome.identity.launchWebAuthFlow({
            // url: `https://discord.com/api/oauth2/authorize?client_id=937186052412678185&permissions=8&redirect_uri=https%3A%2F%2Focdecabdmpigonkcbncodnpgepjjnehm.chromiumapp.org%2F&response_type=code&scope=identify%20email%20guilds%20bot`,
            url: DISCORD_URI,
            interactive: true
        }, function (redirect_uri) {
            // console.log("Background - ", redirect_uri);
            if (chrome.runtime.lastError || redirect_uri.includes('access_denied')) {
                console.log("Could not authenticate.");
                sendResponse('fail');
            } else {
                console.log("Login success - ");
                user_signed_in = true;
                sendResponse('success');

            }

            sendResponse('success');

        });
        /*
        */


        return true;
    }
});

完整代码

4

0 回答 0