Skip to content

Commit

Permalink
Add external OAuth case to browser check (#396)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinSchenkel authored Jun 15, 2023
1 parent 2c99445 commit 89c6a25
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ytmusicapi/auth/headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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


Expand Down Expand Up @@ -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. "
Expand Down
5 changes: 5 additions & 0 deletions ytmusicapi/auth/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""

Expand Down

0 comments on commit 89c6a25

Please sign in to comment.