refactor(OAuth2)!: Rewrite auth module (#661)

This is a rewrite of the OAuth2 module to address some bugs and inconsistencies. And since it changes the structure of the credentials, I'm marking this as a breaking change.

Note that you will have to update your existing credentials, that is if you wish to continue using them. Otherwise, simply delete them and sign in again.
This commit is contained in:
Luan
2024-05-21 18:47:31 -03:00
committed by GitHub
parent 6bb2086875
commit b6ce5f903f
11 changed files with 390 additions and 376 deletions

View File

@@ -131,21 +131,23 @@ export default class HTTPClient {
if (this.#session.logged_in && is_innertube_req && !is_web_kids) {
const oauth = this.#session.oauth;
if (oauth.validateCredentials()) {
await oauth.refreshIfRequired();
if (oauth.oauth2_tokens) {
if (oauth.shouldRefreshToken()) {
await oauth.refreshAccessToken();
}
request_headers.set('authorization', `Bearer ${oauth.credentials.access_token}`);
request_headers.set('Authorization', `Bearer ${oauth.oauth2_tokens.access_token}`);
}
if (this.#cookie) {
const papisid = getStringBetweenStrings(this.#cookie, 'PAPISID=', ';');
if (papisid) {
request_headers.set('authorization', await generateSidAuth(papisid));
request_headers.set('x-goog-authuser', this.#session.account_index.toString());
request_headers.set('Authorization', await generateSidAuth(papisid));
request_headers.set('X-Goog-Authuser', this.#session.account_index.toString());
}
request_headers.set('cookie', this.#cookie);
request_headers.set('Cookie', this.#cookie);
}
}