Skip to content

Token Renew Hook

If you want to add a hook to update the Api token automatically you can do this by passing your own class to the SpotifyApiClient.

Your class has to extend the TokenRenewClass and provide an async __call__() method which returns the new Auth Token.

TokenRenewClass

Class which describes the interfaces the Token renew class has and can also be used to handle basic token renewal

Source code in async_spotify/token_renew_class.py
class TokenRenewClass:
    """
    Class which describes the interfaces the Token renew class has and can also be used to handle basic token renewal
    """

    async def __call__(self, spotify_api_client) -> SpotifyAuthorisationToken:
        """
        **Async** method which gets called if the token is expired

        Args:
            spotify_api_client: The instance of the [`SpotifyApiClient`][async_spotify.api.spotify_api_client]

        Returns: A renewed spotify authorization token
        """

        return await spotify_api_client.refresh_token()

__call__(self, spotify_api_client) async special

Async method which gets called if the token is expired

Parameters:

Name Type Description Default
spotify_api_client

The instance of the SpotifyApiClient

required

Returns: A renewed spotify authorization token

Source code in async_spotify/token_renew_class.py
async def __call__(self, spotify_api_client) -> SpotifyAuthorisationToken:
    """
    **Async** method which gets called if the token is expired

    Args:
        spotify_api_client: The instance of the [`SpotifyApiClient`][async_spotify.api.spotify_api_client]

    Returns: A renewed spotify authorization token
    """

    return await spotify_api_client.refresh_token()

Last update: May 8, 2020