diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2209d36f2..af56d21ad 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -148,8 +148,7 @@ jobs: - name: Set Plex credentials if: matrix.plex == 'claimed' run: | - echo "PLEXAPI_AUTH_MYPLEX_USERNAME=${{ secrets.PLEXAPI_AUTH_MYPLEX_USERNAME }}" >> $GITHUB_ENV - echo "PLEXAPI_AUTH_MYPLEX_PASSWORD=${{ secrets.PLEXAPI_AUTH_MYPLEX_PASSWORD }}" >> $GITHUB_ENV + echo "PLEXAPI_AUTH_SERVER_TOKEN=${{ secrets.PLEXAPI_AUTH_SERVER_TOKEN }}" >> $GITHUB_ENV - name: Bootstrap ${{ matrix.plex }} Plex server run: | diff --git a/plexapi/myplex.py b/plexapi/myplex.py index 07df639e2..c4d8b5551 100644 --- a/plexapi/myplex.py +++ b/plexapi/myplex.py @@ -87,7 +87,7 @@ class MyPlexAccount(PlexObject): key = 'https://plex.tv/users/account' def __init__(self, username=None, password=None, token=None, session=None, timeout=None): - self._token = token + self._token = token or CONFIG.get('auth.server_token') self._session = session or requests.Session() self._sonos_cache = [] self._sonos_cache_timestamp = 0 diff --git a/plexapi/utils.py b/plexapi/utils.py index 08000d58f..9f46cde38 100644 --- a/plexapi/utils.py +++ b/plexapi/utils.py @@ -368,6 +368,10 @@ def getMyPlexAccount(opts=None): # pragma: no cover if config_username and config_password: print('Authenticating with Plex.tv as %s..' % config_username) return MyPlexAccount(config_username, config_password) + config_token = CONFIG.get('auth.server_token') + if config_token: + print('Authenticating with Plex.tv with token') + return MyPlexAccount(token=config_token) # 3. Prompt for username and password on the command line username = input('What is your plex.tv username: ') password = getpass('What is your plex.tv password: ') diff --git a/tests/conftest.py b/tests/conftest.py index 93ca679a0..e5ccc0ac7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -22,6 +22,7 @@ SERVER_BASEURL = plexapi.CONFIG.get("auth.server_baseurl") MYPLEX_USERNAME = plexapi.CONFIG.get("auth.myplex_username") MYPLEX_PASSWORD = plexapi.CONFIG.get("auth.myplex_password") +SERVER_TOKEN = plexapi.CONFIG.get("auth.server_token") CLIENT_BASEURL = plexapi.CONFIG.get("auth.client_baseurl") CLIENT_TOKEN = plexapi.CONFIG.get("auth.client_token") @@ -76,15 +77,15 @@ def pytest_runtest_setup(item): if "client" in item.keywords and not item.config.getvalue("client"): return pytest.skip("Need --client option to run.") if TEST_AUTHENTICATED in item.keywords and not ( - MYPLEX_USERNAME and MYPLEX_PASSWORD + MYPLEX_USERNAME and MYPLEX_PASSWORD or SERVER_TOKEN ): return pytest.skip( - "You have to specify MYPLEX_USERNAME and MYPLEX_PASSWORD to run authenticated tests" + "You have to specify MYPLEX_USERNAME and MYPLEX_PASSWORD or SERVER_TOKEN to run authenticated tests" ) - if TEST_ANONYMOUSLY in item.keywords and MYPLEX_USERNAME and MYPLEX_PASSWORD: + if TEST_ANONYMOUSLY in item.keywords and (MYPLEX_USERNAME and MYPLEX_PASSWORD or SERVER_TOKEN): return pytest.skip( "Anonymous tests should be ran on unclaimed server, without providing MYPLEX_USERNAME and " - "MYPLEX_PASSWORD" + "MYPLEX_PASSWORD or SERVER_TOKEN" ) @@ -99,6 +100,8 @@ def get_account(): @pytest.fixture(scope="session") def account(): + if SERVER_TOKEN: + return get_account() assert MYPLEX_USERNAME, "Required MYPLEX_USERNAME not specified." assert MYPLEX_PASSWORD, "Required MYPLEX_PASSWORD not specified." return get_account()