mirror of
https://github.com/Alvin-Zilverstand/return-youtube-dislike.git
synced 2026-11-30 18:07:53 +01:00
Prepare 4.0.0.3 extension release
This commit is contained in:
1 parent
54ff493ea4
commit
d6cbaadf05
36 files changed
+846
-337
No files matched your search
@@ -235,6 +235,62 @@ api.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
||||
}
|
||||
})();
|
||||
return true;
|
||||
} else if (request.message === "github_oauth_login") {
|
||||
(async () => {
|
||||
try {
|
||||
const idApi = getIdentityApi();
|
||||
if (
|
||||
!idApi ||
|
||||
typeof (idApi.getRedirectURL || (isChrome() && chrome.identity && chrome.identity.getRedirectURL)) !==
|
||||
"function"
|
||||
) {
|
||||
sendResponse({ success: false, error: "identity API not available" });
|
||||
return;
|
||||
}
|
||||
|
||||
const redirectUri =
|
||||
isFirefox() && browser.identity.getRedirectURL
|
||||
? browser.identity.getRedirectURL()
|
||||
: isChrome() && chrome.identity.getRedirectURL
|
||||
? chrome.identity.getRedirectURL()
|
||||
: "";
|
||||
|
||||
const startRes = await fetch(
|
||||
getApiEndpoint(`/api/auth/github/login?redirectUri=${encodeURIComponent(redirectUri)}`),
|
||||
);
|
||||
const startData = await startRes.json();
|
||||
|
||||
const responseUrl = await launchWebAuthFlow(startData.authUrl);
|
||||
const { code, state } = extractOAuthParams(responseUrl);
|
||||
if (!code) {
|
||||
sendResponse({ success: false, error: "No authorization code received" });
|
||||
return;
|
||||
}
|
||||
|
||||
const exchangeRes = await fetch(getApiEndpoint("/api/auth/github/exchange"), {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
code,
|
||||
state,
|
||||
expectedState: startData.state,
|
||||
redirectUri: startData.redirectUri || redirectUri,
|
||||
}),
|
||||
});
|
||||
const authData = await exchangeRes.json();
|
||||
if (authData && authData.success) {
|
||||
handlePatreonAuthComplete(authData.user, authData.sessionToken, () => {
|
||||
sendResponse({ success: true, user: authData.user });
|
||||
});
|
||||
} else {
|
||||
sendResponse({ success: false, error: (authData && authData.error) || "OAuth exchange failed" });
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("github_oauth_login error", e);
|
||||
sendResponse({ success: false, error: String((e && e.message) || e) });
|
||||
}
|
||||
})();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user