mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-27 08:39:23 +00:00
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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user