[GH-ISSUE #675] Github Secrets Cache Handler #397

Open
opened 2026-02-27 23:22:24 +03:00 by kerem · 0 comments
Owner

Originally created by @Peter-Schorn on GitHub (Apr 19, 2021).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/675

I've figured out how to create a cache handler that saves the authorization information to Github secrets. It's implemented in the "secrets-cache-handler" branch of my fork. See #672.

First run this script on your local machine in order to retrieve the token info:

scope = "user-top-read"
spotify = Spotify(
    auth_manager=SpotifyOAuth(
        scope=scope,
        cache_handler=CacheFileHandler()
    )
)

results = spotify.current_user_top_artists()

Then, create a repository secret called SPOTIPY_TOKEN_INFO with the value set to the token info you retrieved from the above script as a string.

Next, create secrets called SPOTIPY_CLIENT_ID and SPOTIPY_CLIENT_SECRET that store your client id and client secret, respectively.

Next, create a personal access token with all of the repo permissions and store it in a secret called PERSONAL_GITHUB_ACCESS_TOKEN.

Screen Shot 2021-04-19 at 1 16 27 AM

And these are the changes I made to the workflow file:

 - name: Run unit tests
      env:
        SPOTIPY_CLIENT_ID: ${{ secrets.SPOTIPY_CLIENT_ID }}
        SPOTIPY_CLIENT_SECRET: ${{ secrets.SPOTIPY_CLIENT_SECRET }}
        PERSONAL_GITHUB_ACCESS_TOKEN: ${{ secrets.PERSONAL_GITHUB_ACCESS_TOKEN }}
        SPOTIPY_TOKEN_INFO: ${{ secrets.SPOTIPY_TOKEN_INFO }}
      run: |
        python -m unittest discover -v tests/unit
Originally created by @Peter-Schorn on GitHub (Apr 19, 2021). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/675 I've figured out how to create a cache handler that saves the authorization information to Github secrets. It's implemented in the "secrets-cache-handler" branch of [my fork][1]. See #672. First run this script on your local machine in order to retrieve the token info: ```python scope = "user-top-read" spotify = Spotify( auth_manager=SpotifyOAuth( scope=scope, cache_handler=CacheFileHandler() ) ) results = spotify.current_user_top_artists() ``` Then, [create a repository secret][2] called `SPOTIPY_TOKEN_INFO` with the value set to the token info you retrieved from the above script as a string. Next, create secrets called `SPOTIPY_CLIENT_ID` and `SPOTIPY_CLIENT_SECRET` that store your client id and client secret, respectively. Next, [create a personal access token][3] with all of the `repo` permissions and store it in a secret called `PERSONAL_GITHUB_ACCESS_TOKEN`. <img width="1182" alt="Screen Shot 2021-04-19 at 1 16 27 AM" src="https://user-images.githubusercontent.com/58197311/115189919-e1520500-a0ac-11eb-8246-8ee0b5aef14c.png"> And these are the changes I made to the workflow file: ``` - name: Run unit tests env: SPOTIPY_CLIENT_ID: ${{ secrets.SPOTIPY_CLIENT_ID }} SPOTIPY_CLIENT_SECRET: ${{ secrets.SPOTIPY_CLIENT_SECRET }} PERSONAL_GITHUB_ACCESS_TOKEN: ${{ secrets.PERSONAL_GITHUB_ACCESS_TOKEN }} SPOTIPY_TOKEN_INFO: ${{ secrets.SPOTIPY_TOKEN_INFO }} run: | python -m unittest discover -v tests/unit ``` [1]: https://github.com/Peter-Schorn/spotipy/blob/secrets-cache-handler/tests/unit/test_secrets_cache_handler.py [2]: https://docs.github.com/en/actions/reference/encrypted-secrets#creating-encrypted-secrets-for-a-repository [3]: https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotipy#397
No description provided.