Add external OAuth case to browser check (#396)

This commit is contained in:
Marvin Schenkel 2023-06-15 20:14:03 +02:00 • committed by GitHub
commit 89c6a2515f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View file

@ -6,7 +6,7 @@ import requests
from requests.structures import CaseInsensitiveDict
from ytmusicapi.auth.browser import is_browser
from ytmusicapi.auth.oauth import YTMusicOAuth, is_oauth
from ytmusicapi.auth.oauth import YTMusicOAuth, is_oauth, is_custom_oauth
from ytmusicapi.helpers import initialize_headers
@ -36,6 +36,9 @@ def prepare_headers(
elif is_browser(input_dict):
headers = input_dict
elif is_custom_oauth(input_dict):
headers = input_dict
else:
raise Exception(
"Could not detect credential type. "

View file

@ -22,6 +22,11 @@ def is_oauth(headers: CaseInsensitiveDict) -> bool:
return all(key in headers for key in oauth_structure)
def is_custom_oauth(headers: CaseInsensitiveDict) -> bool:
"""Checks whether the headers contain a Bearer token, indicating a custom OAuth implementation."""
return "authorization" in headers and headers["authorization"].startswith("Bearer ")
class YTMusicOAuth:
"""OAuth implementation for YouTube Music based on YouTube TV"""